How to carry attachments from old RITM to the new RITM under the same Request

Devika3
Tera Guru

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.

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Devika3 

Please share your script here

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

var ritm = new GlideRecord('sc_req_item');  
ritm.addQuery('request', current.request);  
//gs.log('Attchment test' + current.request.number);
ritm.addQuery('short_description','RITM1 sd');
//ritm.addQuery('u_custom_description', current.u_custom_description);
gs.log('custom desc is ' + current.u_custom_description);
ritm.query();
while(ritm.next())  
{
    var atchmt = new GlideRecord('sys_attachment');
atchmt.addQuery('table_sys_id',ritm.sys_id);    
 GlideSysAttachment.copy('sc_req_item', ritm.sys_id, 'sc_req_item', current.sys_id);
   }

















// // gs.log('%%%RITM to Attachment created test not');
// // var StringUtil = Packages.com.glide.util.StringUtil;
// // var encData = null;
// // var name = null;
// // var type = null;
// // var cid = null;
// // var sysid = null;
// // var gra = new GlideRecord('sc_req_item');
// // gra.addQuery('request',current.request);
// // gs.log('RITM attachment test +' + current.request);
// // gra.addQuery('short_description','Request new Material / Part creation');
// // gra.query();
// // if(gra.next()){
// //   gs.log('RITM attachment + ' +gra.number);
// //   cid = gra.sys_id;
// // }
// // var gr = new GlideRecord("sys_attachment");
// // gr.addQuery('table_sys_id',cid);
// // gr.query();
// // gs.log('RITM attachment+ ' + gr.table_sys_id);
// // while(gr.next())
// //   {
// //   var sa = new Packages.com.glide.ui.SysAttachment();
// //   var binData = sa.getBytes(gr);
// //   encData = StringUtil.base64Encode(binData);
// //   name = gr.file_name;
// //   type = gr.content_type;
   
// //   var StringUtil = Packages.com.glide.util.StringUtil;
// //   var value = StringUtil.base64DecodeAsBytes(encData);
// //       gs.log("%%%RITM to Attachment created : " +current.sys_id+", "+ name+", "+ type+', '+ value);
// //   var attachment = new Attachment();
// //   attachment.write('sc_req_item', current.sys_id, name, type, value);
// //   current.update();
// //   name = null;
// //   type = null;
// //   encData = null;
// // }