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-03-2024 04:24 AM
Can you put logs in BR for where exactly it's failing...? If attachment is available on RITM when BR is running or nor that we have to verify it...if it took sometime for attachment transfer from item to RITM then add gs.sleep(60) in BR at first line..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 05:42 AM
Hi @Mani
I'm trying with below script but in logs showing "No attachments found on the current record."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 08:57 AM - edited 10-03-2024 08:59 AM
So no attachment available on RITM
Please make sure attachment is added on item and it should available on RITM
Please send screenshot of RITM .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 11:26 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2024 01:30 AM
Hi @Mani A
when we are raising request from portal with attachment that attachment taking time to get attach from Item to on RITM Table. That' why in logs showing "No attachment found on RITM table".
I tried Retry Mechanism: The script retries up to 5 times (or any other number you set) to check for the attachment on the RITM. Each retry waits for 2 seconds (gs.sleep(2000)), allowing time for the attachment to be processed and linked to the record.
Conditional Import: The import process is only triggered if an attachment is successfully found within the retry loop.
How it Works:
The script checks if an attachment exists on the RITM.
If no attachment is found, it waits for 2 seconds and tries again.
This process repeats up to 5 times (or until an attachment is found).
If after all retries no attachment is found, it logs a failure message.
// Retry mechanism for checking attachments
var maxRetries = 5; // Number of retries
var retryCount = 0;
var attachmentFound = false;
// Loop until attachment is found or max retries reached
while (retryCount < maxRetries && !attachmentFound) {
gs.log('Attempt ' + (retryCount + 1) + ' to find attachments on RITM: ' + current.sys_id, 'Attachment Import Script');
// 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 (ritmAttachment.next()) {
gs.log('Attachment found on RITM after ' + (retryCount + 1) + ' attempt(s)', 'Attachment Import Script');
gs.log('Copying attachment from RITM: ' + ritmAttachment.sys_id + ' to data source: ' + dataSourceSysId, 'Attachment Import Script');
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', dataSourceSysId);
attachmentFound = true; // Break loop if attachment is found
} else {
gs.log('No attachments found on RITM: ' + current.sys_id + ' (Attempt ' + (retryCount + 1) + ')', 'Attachment Import Script');
retryCount++;
gs.sleep(2000); // Wait for 2 seconds before retrying
}
}
if (!attachmentFound) {
gs.log('Failed to find any attachments on RITM after ' + maxRetries + ' attempts', 'Attachment Import Script');
}
// Trigger the scheduled import if an attachment was found
if (attachmentFound) {
var schimp_GR = new GlideRecord('scheduled_import_set');
schimp_GR.addQuery('data_source', dataSourceSysId);
schimp_GR.query();
if (schimp_GR.next()) {
gs.log('Triggering scheduled import for data source: ' + dataSourceSysId, 'Attachment Import Script');
SncTriggerSynchronizer.executeNow(schimp_GR);
} else {
gs.log('No scheduled import set found for data source: ' + dataSourceSysId, 'Attachment Import Script');
}
}
But still the attachment not found on RITM Table. Any other approach we can try ?
Thanks
JM