- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2020 08:02 AM
Hi All,
I have a variable set which has two variables - Requested For and Requested By (Reference to user table).
I want to set the values of these variables to the Requested For and Opened by fields of RITM.
I do not want to specify in the workflow since in all of the workflow these workflow is used I need to modify all of those workflows.
Is there a way I can write a script at a variable set level so that code will be applied in all of the catalogs in which this variable set is used?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2020 11:49 AM
So did a quick test.
Business Rule
Table: sc_req_item
Insert = true
When: Async
Condition:
current.request.requested_for != current.variables.requested_for
Script:
(function executeRule(current, previous /*null when async*/) {
var grREQ = new GlideRecord('sc_request');
grREQ.get(current.getValue('request'));
grREQ.setValue('requested_for', current.variables.requested_for);
grREQ.update();
})(current, previous);
Works instantly.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2020 08:06 AM
Hi there,
You could set up a before insert business rule on the sc_req_item table. Would that be something for you?
Do note, requested for out-of-the-box is used on the Request, not on the Requested Item. So below code won't just work if you copy/paste. Maybe you have a custom field? Or maybe indeed you are actually after the Request. That's up to you.
Something like below:
current.requested_for = current.variables.requested_for;
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2020 08:19 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2020 08:23 AM
That's coming from the Service Portal widget.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2020 09:43 AM
Requested for field is an extended field from sc_request table. so, below statement is not working.
current.request.requested_for = current.variables.requested_for;
Even I tried with GlideRecord but no luck. My variable name is right. It is inside a variable set.
//current.request.requested_for = current.variables.requested_for;
var gr = new GlideRecord('sc_request');
gr.addQuery('sys_id',current.request);
gr.query();
current.comments = current.request;
current.comments = gr.getRowCount();
while(gr.next())
{
current.comments = gr.number;
gr.requested_for = current.variables.requested_for;
gr.update();
}