- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 08:50 AM
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);
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2019 06:49 AM
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);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 09:15 AM
Can I recommend a better way to avoid duplicates: https://community.servicenow.com/community?id=community_blog&sys_id=adfce2a5dbd0dbc01dcaf3231f961934...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 10:58 AM
Hello Michael,
I saw this but it uses the parent field off task which is the RITM number, in this case since we are generating a new request the RITM will be a different number.
Thanks,
Chad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 05:09 AM
rc.sys_id will return you request sys_id, not the catalog task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 05:17 AM
Please refer below thread as cart.placeOrder(); returns request object not sc object