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

GlideFather
Tera Patron

Olá @mansigoel,
and where is this script - is it a BR or what it is?

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


This is written in Script include.

and how is the script include called?

Wouldn't it be easier to achieve this by a business rule or a flow maybe?

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


how can we achieve using BR?