How to carry attachments from old RITM to the new RITM under the same Request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 01:14 AM
Hi All,
We have a catalog form ,once we submit the REQ1 it will create an RITM1. And after the closure of the RITM1, another RITM2 will be created through the workflow under another request(REQ2). But we are transferring the new RITM2 to the REQ1 of the old RITM1.
Now the requirement is to carry over all the attachments and comments from RITM1 to RITM2. I have created the Business rule for the same, but unfortunately not able to establish a link between RITM1 and RITM2. Because while creation of RITM2 it is under REQ2. Hence I am not able to find the attachments and comments from RITM1 .
The log statements are giving REQ2 as the request of RITM2, even i tried giving sleep seconds.
Please let me know if anyone encountered it before.
Thanks in advance.
Regards,
Devika.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 01:19 AM
Hello,
In workflow store the sys_id of the RITM2 in an variable. Now lookup for the record using sys_id then you can use below API to copy all attachments from one record to another record.
https://developer.servicenow.com/dev.do#!/reference/api/utah/server/no-namespace/c_GlideSysAttachmen...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 02:22 AM
Hi Mahesh,
I have created a custom field which has the value : desc RITM1 number and i am passing the same value to RITM2 through workflow, but even in that case this is coming as empty during insertion of the new RITM2. I tried giving the log statements, but it is giving empty value in the business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 01:42 AM
HI @Devika3 ,
I trust you are doing great.
You can take reference of below script which we have implemented in our project.
(function executeRule(current, previous /*null when async*/) {
// Check if the current RITM has a reference to another RITM
if (current.reference_to_ritm1.nil()) {
return;
}
var ritm1_sys_id = current.reference_to_ritm1.sys_id.toString();
// Copying attachments from RITM1 to RITM2
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_sys_id', ritm1_sys_id);
attachmentGR.query();
while (attachmentGR.next()) {
var attachment = new GlideSysAttachment();
attachment.copy('sc_req_item', ritm1_sys_id, 'sc_req_item', current.sys_id.toString());
}
// Copying comments from RITM1 to RITM2
var journalGR = new GlideRecord('sys_journal_field');
journalGR.addQuery('element_id', ritm1_sys_id);
journalGR.query();
while (journalGR.next()) {
var newJournal = new GlideRecord('sys_journal_field');
newJournal.initialize();
newJournal.element_id = current.sys_id.toString();
newJournal.element = journalGR.element.toString();
newJournal.value = journalGR.value.toString();
newJournal.insert();
}
})(current, previous);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 02:32 AM
Hi Amit,
reference_to_ritm, is it a new field created?
I have created a new custom field and tried giving the value 'desc RITM1 number' through the workflow, but the variable is showing empty in RITM2 during insertion of the record. I tried giving log statements, the field is empty.