- 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-12-2017 05:09 AM
Thank you for the info. Here's the next question... what would you like to do if you have multiple RITMs on the REQ (sc_request)? It's a 1-many relationship so there's no guarantee that you will only have one RITM with that variable.
Next question... what would you like to do if that variable doesn't exist?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2017 06:22 AM
Since the variable is mandatory this should be filled and only one ritm will be there in a n req

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2017 06:28 AM
If you just need to update the parent request, then your script is pretty simple.
var ritm = new GlideRecord('sc_req_item');
if (ritm.get('request', current.getValue('request')) {
current.requested_for = ritm.variables.WD_sa_requested_for;
}
Put that in a BEFORE business rule since we're updating values on the current record (sc_request.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 12:35 AM
Hi Chuck,
I user a before insert-update BR on sc_request table.
Condition: current.short_description== 'New Hire Request'
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ritm = new GlideRecord('sc_req_item');
if (ritm.get('request', current.getValue('request')))
{
current.requested_for = ritm.variables.WD_sa_requested_for;
current.update();
}
})(current, previous);
But this is not working.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 05:31 AM
Rule #1 about business rules... don't use current.update() as a general rule.
If you're using it in a BEFORE rule, you're triggering the "save" and all the same BRs again which react to insert() and update(). With a BEFORE rule, you get the update() for free - that's why it's called a BEFORE business rule, because you are making changes right BEFORE the save.
If you are using a current.update() in an AFTER rule, you're probably doing it wrong and the logic most likely should be in a BEFORE rule. Although there are RARE exceptions.
Go to System Diagnostics> Debug Business Rules and verify that your BR is triggering (i.e. the condition is met) and that will tell if the script is running. If so, set breakpoints and inspect your script as it runs using the script debugger.