- 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-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