- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2020 02:23 AM
Hi All,
When User1 submits the catalog Request with Requested For as REQUser1, then in REQ and RITM form Requested For is getting changed to User1
But if i impersonate user to any other user say USER2, then its working fine. whatever was mentioned requested for on the catalog form its getting populated same in REQ and RITM form.
This is occurring for a particular user. Can anyone please help to understand why it is happening.
Regards,
Ak
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2020 02:57 AM
Do note that post was only about sc_request. So you also need to add a query for your sc_cart.
An extract from that post:
---
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-23-2020 02:46 AM
This is happening with a particular user
I have overridden that OOB Requested for thing with the below script .
//Onchange of Requested for
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Overiding the default script for requested_for.
if (newValue) {
var gr = new GlideRecord('sc_cart');
gr.addQuery('user', g_user.userID);
gr.query();
gr.next();
gr.requested_for = newValue;
g_form.setReadOnly(gr.requested_for);
gr.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2020 02:56 AM
Ah indeed, you are trying to overwite the out-of-the-box default value.
Do consider an alternative approach for this. onChange fields a bit strange to me. Is the sc_cart record at that moment already available?
Also, you are performing GlideRecord queries within client side scripting. This is not advisable. Read about it in this article I wrote a while ago:
Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!
An alternative, might be to update the values through after or async business rule. See also below question which I recently replied with such an solution:
https://community.servicenow.com/community?id=community_question&sys_id=3b1c72b01b1c5010a59033f2cd4b...
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-23-2020 02:57 AM
Do note that post was only about sc_request. So you also need to add a query for your sc_cart.
An extract from that post:
---
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-23-2020 03:45 AM
thank you so much it working as expected.
But still i didn't get, why Requested for was reflecting correctly on sc_request & sc_req_item table for other user.
Thanks & Regards,
Ak

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2020 03:51 AM
Well if you want to know that more, that you would need to investigate multiple things. For example, was only the sc_cart set correct, and the sc_request not. Where the used test cases identical, just only a different user. Did the onChange GlideRecord query got triggered. Etc, etc..
Don't think it's worthwhile investigating. As like I mentioned, the choice for onChange client script is odd + it contained a GlideRecord query. So that would certainly not be a way to go.
At least good to hear it works fine now.
Please mark this answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.
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