- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2019 03:32 AM
Hello All,
I am trying to copy a location catalog variable on Request item and request form.
I have written the below code.
I have a run activity on request item workflow which is trying to set the location variable on scratchpad.
Run script activity on workflow.
Then I am running a after business rule on request item table to set the location variable value on request item form and request form’s filed called location.
But this script is not working, I have tried multiple thing but unable to do so.
Can anyone help me over here?
Regards,
Priyanka
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2019 05:23 AM
If I understand it correct you would like to update location field on RITM and Request using the location variable
Try the below script in Run script
//Update location field on RITM
current.location = current.variables.location;
//Update location field on Request
var gr = new GlideRecord("sc_request");
gr.addQuery("sys_id", current.request);
gr.query();
if (gr.next()) {
gr.location = current.variables.location;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2019 03:54 AM
When i was testing adding RITM's via API i found that you have to add the variable in to the sc_item_option table and then relate it to the RITM in the sc_item_option_mtom table. This is the script i was testing with in a fix script. You could probably co-opt it somehow but it might be better to run it in a script activity in the workflow rather than in a BR, you need to update the record to trigger the BR whereas you can trigger it however you want in the WF.
var itemGr = new GlideRecord("sc_req_item");
itemGr.initialize();
itemGr.cat_item = 'sys_id of catalog item';
itemGr.request = 'sys_id of master request';
itemGr.state = 1;
var reqItem = itemGr.insert();
var optionGr = new GlideRecord('sc_item_option');
optionGr.initialize();
optionGr.item_option_new = 'sys_id of variable';
optionGr.value = 'value or variable;
var itemID = optionGr.insert();
var relGr = new GlideRecord('sc_item_option_mtom');
relGr.initialize();
relGr.request_item = reqItem;
relGr.sc_item_option = itemID;
relGr.insert();
var startWF = new GlideRecord('sc_req_item');
if(startWF.get(reqItem)){
startWF.setForceUpdate(true);
startWF.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2019 04:41 AM
Hi,
I am little bit confused! You are setting the value of location in a workflow scratchpad variable and then trying to use it in a business rule.. I don't think it will work, because only g_scratchpad variables are available for use in a business rule then also it should be initialized from a display BR.
Correct me if I am wrong.
Thanks,
Subhadip
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2019 11:20 PM
Hello TheKid,
I have taken the reference from below link:-
https://docs.servicenow.com/bundle/london-application-development/page/script/useful-scripts/reference/r_AcsWrkflowSPBR.html
Please read it and let me know if i did anything wrong over here.
Regards,
Priyanka

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2019 05:23 AM
If I understand it correct you would like to update location field on RITM and Request using the location variable
Try the below script in Run script
//Update location field on RITM
current.location = current.variables.location;
//Update location field on Request
var gr = new GlideRecord("sc_request");
gr.addQuery("sys_id", current.request);
gr.query();
if (gr.next()) {
gr.location = current.variables.location;
gr.update();
}