
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2020 09:35 PM
Hi guys, could you help me, by default, when i try to order from catalog item field "requested for" filling by logged in user, i would like to change it from a variable ?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2020 09:39 PM
Create a before business rule on table sc_request with below details.
Table: sc_request
When to run: Before
Insert: Checked
Advanced > Condition : Empty
Script:
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request', current.sys_id);
grRITM.query();
while (grRITM.next()) {
if (!JSUtil.nil(grRITM.variables.requested_for)) { //assuming requested_for is the name of your catalog variable. Replace this exactly with the name of catalog variable you have.
current.requested_for = grRITM.variables.requested_for; /assuming requested_for is the name of your catalog variable. Replace this exactly with the name of catalog variable you have.
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2020 09:39 PM
Create a before business rule on table sc_request with below details.
Table: sc_request
When to run: Before
Insert: Checked
Advanced > Condition : Empty
Script:
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request', current.sys_id);
grRITM.query();
while (grRITM.next()) {
if (!JSUtil.nil(grRITM.variables.requested_for)) { //assuming requested_for is the name of your catalog variable. Replace this exactly with the name of catalog variable you have.
current.requested_for = grRITM.variables.requested_for; /assuming requested_for is the name of your catalog variable. Replace this exactly with the name of catalog variable you have.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 03:26 PM
This worked perfectly, however now I have the problem of it leaving the approvers related to the person who created it. How do we address checking/changing the approving manager?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2020 09:39 PM
Hi there,
Have a look at the default value for the Requested for on Request.
Out-of-the-box default value:
javascript:gs.getUserID()
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
05-31-2020 09:40 PM
Hi,
That's because the field has default value as logged in user in dictionary
if this is for your specific catalog item only then you can update it via the workflow on your catalog item with that variable value
Avoid using Business rule as this is only for your catalog item
Use Run Script activity in workflow
sample script below
Note: Ensure you use proper variable name
var user = current.variables.<variableName>;
var req = new GlideRecord('sc_request');
req.get(current.request);
req.requested_for = user;
req.update();
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader