I want to copy the attachments from catalog form to incident

mansigoel
Tera Contributor

Hello,

 

I am trying the scenario that whenever the attachment is attached on the catalog form and the user has selected incident in the dropdown option in one of the fields in catalog form, then I will check from attachment table which is the latest attachment attached to sc_cart_item and then copy it.

 

Script for reference:

var sourceAttachmentGlideRecord = new GlideRecord('sys_attachment');
  sourceAttachmentGlideRecord.addEncodedQuery('table_name=sc_cart_item^sys_created_by=' + gs.getUserName() + '^sys_created_on>=javascript:gs.minutesAgo(5)');
            //sourceAttachmentGlideRecord.addQuery('sys_id', dataObj.attachment);
            sourceAttachmentGlideRecord.query();
            while (sourceAttachmentGlideRecord.next()) {
           .....}
 
But, since within 5 mins, the user can raise 2 requests and have multiple attachments attached. How can I filter out this? 
I am not able to think of any other solution.
Please help. 
7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@mansigoel 

so there is a variable which refers to incident table.

User is attaching file using OOTB paper-clip icon?

If yes then whenever user submits request, the attachments added while submission gets attached to RITM record

You can have after insert business rule on RITM table and have this logic

Business Rule: After Insert

Condition: current.cat_item.name == 'Your Item Name Here'

Script:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    new GlideSysAttachment().copy('sc_req_item', current.sys_id, 'incident', current.variables.variableName); // give here the variable name which refers to incident table

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@mansigoel 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi Ankur,

 

No. its not being copied on any RITM. I am inserting a new record in incident directly after submission of the request.