Auto-import attached CSV file from RITM Table to datasource table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 08:36 AM
Hi Team,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 04:18 AM
(function executeRule(current, previous /*null when async*/) {
// Define the data source sys_id
var dataSourceSysId = '8bbeb3f133389250b3e0b4023d5c7b8a';
// Check for existing attachments on the data source
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_name', 'sys_data_source');
attach.addQuery('table_sys_id', dataSourceSysId);
attach.query();
// Delete existing attachments
while (attach.next()) {
attach.deleteRecord();
}
// Check for attachments on the RITM (Service Request Item)
var ritmAttachment = new GlideRecord('sys_attachment');
ritmAttachment.addQuery('table_name', 'sc_req_item');
ritmAttachment.addQuery('table_sys_id', current.sys_id);
ritmAttachment.query();
// If RITM has attachments, copy the first one to the data source
if (ritmAttachment.next()) {
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', dataSourceSysId);
}
// Trigger the scheduled import
var schimp_GR = new GlideRecord('scheduled_import_set');
schimp_GR.addQuery('data_source', dataSourceSysId);
schimp_GR.query();
if (schimp_GR.next()) {
SncTriggerSynchronizer.executeNow(schimp_GR);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 07:28 PM
Hi @Mani A
The above provided Script is working in my PDI. But not working in my Company Dev instance, till Delete existing attachments part it's working but unable to insert attachment from RITM to Data source Table.
Thanks
JM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 08:06 PM
Which BR created ?
After insert/update BR on RITM table with state changes to open or something
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 09:26 PM