- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2022 12:53 AM
Hi,
I have the following code working for a user submitting a catalogue item:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '' || window) {
return;
}
// check if we are in an order guide using the g_service_catalog api for Service Portal and Mobile
var isOrderGuide = g_service_catalog.isOrderGuide();
if(!isOrderGuide) {
SetRequester();
}
}
function SetRequester()
{
var requester = g_form.getValue('requested_for');
g_form.setValue('req_requested_for', requester);
}
Basically it is checking if it is not an order guide and if that is the case then it will copy data between one field and another.
However, when I use the "Try it" button on the backend (native UI) or have an automation that runs on the backend it throws an error: "ReferenceError: g_service_catalog is not defined"
I have written a workaround for this as below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '' || window) {
return;
}
try {
// check if we are in an order guide using the g_service_catalog api for Service Portal and Mobile
var isOrderGuide = g_service_catalog.isOrderGuide();
if(!isOrderGuide) {
SetRequester();
}
} catch(e) {
if(e.toString() == "ReferenceError: g_service_catalog is not defined") {
SetRequester();
}
}
}
function SetRequester()
{
var requester = g_form.getValue('requested_for');
g_form.setValue('req_requested_for', requester);
}
However, this is not an adequate solution. Would anyone have any clue why I am getting the above error in the backend but not the frontend? I need to be able to discern an order guide from a normal catalogue item.
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2022 11:13 PM
something like this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '' || window) {
return;
}
var url = top.location.href;
if(url.indexOf('sc_cat_item_guide') == -1){
var requester = g_form.getValue('requested_for');
g_form.setValue('req_requested_for', requester);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2022 12:58 AM
Check this
https://community.servicenow.com/community?id=community_question&sys_id=34c29333db1e10107d3e02d5ca961905
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2022 06:18 PM
I wish I could mark comments as unhelpful, because this would surely get that mark... I have checked that community post previously and is wholly unhelpful, as you could see if you actually read my post, I am already successfully using the code they discuss... I am having an issue with an error appearing when the client script is run by the backend, and not the frontend, of servicenow. Please read a post and make sure you understand it before commenting unhelpfully and clogging the feed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2022 01:00 AM
Hi,
you can check the URL and see if it's an order guide and based on that take the decision
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2022 06:16 PM
How would I go about doing this?