Attachments not getting added to newly created request items or incidents
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 12:30 AM
Hi Team,
I have implemented functionality to create requests and incidents through data source and transform map triggering an event queue schedule in workflow . This process is initiated as part of bulk creation workflow based on data source(csv file).
Now, I want to copy the attachment to the created requests /incidents . However, I want to exclude the CSV file used for bulk creation form being copied as an attachment.
Please find my script :I have created on after script in transform map for request creation and for incident i directly mapped fields and creating incidents but i want to copy attachments from bulk creation form or request item to newly created incidents
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var cartId = GlideGuid.generate(null);
var sd= source.u_shortdescription;
gs.log("short desc snt"+sd);
var cart = new Cart(cartId);
var item = cart.addItem(gs.getProperty('x.item'));
cart.setVariable(item,'short_description', sd);
var rc = cart.placeOrder();
gs.log( "Number is :" + rc.sys_id);
//var website=new GlideRecord('cmdb_ci_web_site');
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", rc.sys_id);
gr.query();
if (gr.next()) {
ritmSysId = gr.getUniqueValue();
}
source.sys_target_table - gr.sys_class_name;
source.sys_target_sys_id = ritmSysId;
source.update();
ignore = true;
}
)(source, map, log, target);
Thank you in Advance.
Regards,
Srinath.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 07:05 AM
are you getting attachment data in the excel file itself? i.e. file name, file type, base64Encoded data?
what's your business requirement?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 08:27 AM
Hi @Ankur Bawiskar , My requirement is using Bulk catalog request form need to create multiple requests based on CSV File and above script is working fine , there is another scenario requester will attach other attachments(Excel, pdf, word document) as well so attachments need to copy for all newly created RITMs but when I use this line of code creating multiple requests (not as per the CSV File) var gr1 = new GlideSysAttachment().copy('sys_data_source', 'sys_id of data source', 'sc_req_item',ritmSysId);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 10:10 PM
in your onAfter transform script you won't know the RITM which got submitted and would be trickier to determine the RITM and hence won't know the file
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 02:58 AM
@Ankur Bawiskar , I am copying the all the attachment from ritm to data source and copying datasource to newly created ritms . Is there any way to exclude csv file and copy other attachments to newly created items , i have tried below method but not working and getting correct sysid
var attachment = new GlideSysAttachment();
//set up inputs
var rec = new GlideRecord('incident');
rec.get('78271e1347c12200e0ef563dbb9a7109');
var fileName = 'example.txt';
var contentType = 'text/csv';
var content = 'The text that is stored inside my file';
var agr = attachment.write(rec, fileName, contentType, content);
gs.info('The attachment sys_id is: ' + agr);
By using below article also i have tried to get column wise data but not working and getting row wise data
In CSV file we have cmdb website data, we need query website table and map newly created RITMs assignment group and CI requested for.
Please let me know is there any other to achieve this scenario.