- 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 11:31 AM
Yes that's exactly what I already mentioned. Out-of-the-box requested_for is on the Request, not on the Requested Item.
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 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:09 AM
Hi,
By default the system take current session of the user to set the opened by field.
Why you want to override that?
If you still want to do that then write a business rule on the RITM Table before insert.
Script will be:
current.opened_by = current.variables.requested_by;
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2020 08:20 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2020 08:09 AM
Hi,
Refer this it will help you
Thanks,
Kunal