- 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
05-06-2016 03:24 PM
That makes sense. Time to take another approach. Put the business rule on sc_request (no condition, after, insert) and put similar logic in there.
- Check for any related sc_req_item records of the right type
- Take the variables from the record found and place them on current.
Ex:
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item', <your cat item sys_id>);
ritmaddQuery('request', current.getValue('sys_id'));
ritm.query();
if (ritm.next()) {
current.u_requested_for = ritm.variables.requested_for; // substitute your variable & field here
current.setWorkflow(false);
current.update();
}
Still not sure that will work since all the request items may not yet be linked. You'll have to experiment and let us know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2016 03:28 PM
Could just change logic on "sc_req_item" BR to update and if request field changes and is not empty..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2016 01:33 PM
This blog was very helpful! Makes a bit more sense now that I understand the Request is not created first. But now I have another issue (besides the fact that I haven't yet successfully copied my variables to the Request fields).....my Requested Items are running the correct workflow, but my Requests are not. What I can't determine is where I would change the Requests workflow. I understand that the workflow engine triggers the Request workflow but where is it configured?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2016 02:12 PM
Can you share your business rule and the when its going to run?
The request workflow will be under the workflow model. The name should be "Service Catalog Request" By default it runs all the time OOTB. Do you know if it's been changed?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2016 01:16 PM
If this is for a catalog item you can create a workflow and add a Core activity of Catalog Task. In that catalog task select the Advanced checkbox and there you can use the Advanced script to copy values from the item (current) to the request, for instance:
sc_request.u_requested_for = current.u_requested_for;