- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2016 12:30 PM
I've seen this topic in the community a lot, but no straight answers on how to accomplish this.
I have two variables in a Service Catalog item that I need to copy to a field in the Request (sc_request). Is this possible? I've tried writing a Business Rule, a variable client script, etc. I cannot copy these variables contents into a Request field.
Thanks in advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2016 01:59 PM
Kari,
Write a Before Insert Business rule on sc_request table and add the following script in there. The following script copies all the questions and their values of all the requested items into description field on the request form
var gr= new GlideRecord("sc_req_item");
gr.addQuery('request',current.sys_id);
gr.query();
var varArr='';
while(gr.next()){
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(gr.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if(vs.get(i).getLabel() != '') {
varArr+=vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue()+'\n';
}
}
}
current.description=varArr;
Thanks,
Abhinay
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2017 01:40 AM
Thanks for this information Chuck .
But even if I commented current.update(); its not working.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2017 06:14 AM
Sorry, I meant to type more about the solution before hitting save.
First thing to check is if your variable actually has a value.
inside the if statement, add a line something like this then check the logs.
gs.info('>>>DEBUG: WD_sa_requested_for: ' + ritm.variables.WD_sa_requested_for);
Alternatively you can use the script debugger to set a break point and investigate the values of the variables and fields.
Second thing, check the log for any errors. It may be complaining and you're not seeing it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2018 02:08 AM
Hello Abhinay,
How we can exclude the questions(variables) which are null.
Please suggest.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2016 09:20 AM
I tweaked the script just a bit to accomplish what I needed. Much thanks to all of your for your input, time & help!
This is a Business Rule in the sc_request table running Before Insert. This script completes the Short Description and Description field from the Variables on the request form in the catalog:
var gr= new GlideRecord("sc_req_item");
gr.addQuery('request',current.sys_id);
gr.query();
var varArr='';
while(gr.next()){
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(gr.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if(vs.get(i).getLabel() != '') {
varArr+=vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue()+'\n';
}
}
}
current.short_description=gr.variables.Request_title;
current.description=gr.variables.description;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2017 11:11 AM
This script works thanks, but how can I only show variables that equal true and hide "= true"