
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2017 04:08 PM
Hello,
I am trying copy all the Request Items number and short description name, to the description field and comments field of the Request (parent) when the Request is created. This will hopefully help users understand what items were ordered in their Request.
So I am adding an 'Activity Properties: Run Script' to the OOB Workflow 'Service Catalog Request' and have tried to find scripts in the community that might work; I am weak at JavaScript. I am not positive but I am thinking that my gr.addQuery('request',current.sys_id); is getting the Workflow sys_id and not the Request's sys_id, but I am not positive. Do you know how I can get the Request's sys_id or what may be wrong with my script?
function getItems() {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request',current.sys_id);
gr.query();
while(gr.next())
gr += '\n' + gr.number() + ": " + gr.getDisplayValue();
//gr += '\n' + gr.number() + ": " + gr.getDisplayValue() + "- " + gr.short_description.getValue();
}
current.description = gr
current.comments = gr
Thank you,
Wesley
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 09:27 AM
Use this code
var arr=[];
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request',current.sys_id);
gr.query();
while(gr.next()){
arr.push(gr.number+': '+gr.short_description);
}
current.description='REQUESTED Items:'+arr.join("\n");
current.comments='REQUESTED Items:'+arr.join("\n");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2017 04:50 PM
Hello Wesley,
Use the below script.
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request',current.sys_id);
gr.query();
while(gr.next())
{
current.description = gr.number;
current.comments = gr.short_description;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 09:17 AM
Hi Pradeep,
Awesome! It is working for the 'Description' field, but having problems in writing to the Additional Comments or Work Notes field. Neither work, am I missing something?
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request',current.sys_id);
gr.query();
current.description = 'REQUESTED ITEMS:';
while(gr.next())
var cd = current.description + '\n';
current.description = cd + gr.number + ": " + gr.short_description;
current.comments = gr.short_description;
current.work_notes = gr.short_description;
Thank you,
-Wesley

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 09:27 AM
Use this code
var arr=[];
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request',current.sys_id);
gr.query();
while(gr.next()){
arr.push(gr.number+': '+gr.short_description);
}
current.description='REQUESTED Items:'+arr.join("\n");
current.comments='REQUESTED Items:'+arr.join("\n");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 10:10 AM
Hi Abhinay,
Bingo, it works! Thanks! If I have it correct, to write to the Additional Comments or Work Notes fields my data needed to be put into an array? Is that correct?
-Wesley