Copying attachments from one sc_task to another sc_task

Chad Wilhelm1
Tera Expert

Hello,

We have a business requirement to copy attachments from one sc_task to another sc_task.   We currently have a catalog item that creates a sc_task for a request for quote then once the sc_task is closed complete the UI Action Purchase is available which then creates another request copying the variables from the first request.   I tried to add the copy attachment code below in yellow.   Any assistance would be appreciated

UI Action

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('de44ce8013d41bc0fa7c73076144b09d'); //GTO Procurement - Quote/Purchase/Return Request

//iterate through all properties of current.request_item.variables set them as the values for the new request
for (var property in current.variables){
if (property == 'request_type')
cart.setVariable(item, property, "Purchase");
else
cart.setVariable(item, property, current.variables[property]);
}

var rc = cart.placeOrder();
gs.addInfoMessage("Purchase request has been submitted. Request number is " + rc.number);
GlideSysAttachment.copy('sc_task',current.getUniqueValue(),'sc_task',rc.sys_id);
rc.update();
action.setRedirectURL(current);

1 ACCEPTED SOLUTION

Chad Wilhelm1
Tera Expert

I was able to go it to work.

var newSerReqTask = new GlideRecord('sc_task');
var taskQueryString = "request=" + rc.sys_id;
newSerReqTask.addEncodedQuery(taskQueryString);
newSerReqTask.query();

//While there is a record found from the above query, add all attachments from the Quote Catalog Task to the new Purchase Catalog Task
while (newSerReqTask.next()){
var gsAttach = new GlideSysAttachment().copy('sc_task', current.sys_id, 'sc_task', newSerReqTask.sys_id);
}

View solution in original post

12 REPLIES 12

Is this an UI actions? I was not able to get this to work; nothing happened.

 

find_real_file.png

Hi @Chad Wilhelm1 ,

 

Should this be written in business rule or in an UI action?

 

Hi @Ankur Bawiskar, could you help us on this?

 

Thanks.

@amogh_b6 

can you post a new question and share all the details there and tag me there as this is an older thread?

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