- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2017 09:51 AM
Hi Community,
I've seen a couple threads regarding hiding variables for a catalog item when they are included in an order guide. I'm using a catalog client script and it appears correct to me, but it's not working.
Anyone see a problem with my script or know what might be preventing this from working? I'm not seeing the alert in the script either, so it leads me to believe the system is not picking up the client script in the order guide.
function onLoad() {
//Hiding fields on order guide but keeping visibility on request item
var isOrderGuide = g_service_catalog.isOrderGuide();
alert(isOrderGuide);
if(isOrderGuide){
g_form.setMandatory('ReqType',false);
g_form.setMantatory('Affected_Employee',false);
g_form.setDisplay('ReqType',false);
g_form.setDisplay('Affected_Employee',false);
}
}
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2017 10:34 AM
I tried using this in my Jakarta PDI:
function onLoad() {
//Type appropriate comment here, and begin script below
var isOG = g_service_catalog.isOrderGuide();
alert(isOG);
}
In the platform UI, I am getting an error stating 'g_service_catalog' is undefined, and in SP the evaluation is returning nothing. I checked here:https://developer.servicenow.com/app.do#!/document/content/app_store_doc_sp_widget_scripts_istanbul_...
It appears 'g_service_catalog' is only available in SP in Istanbul and above.
The other way you might go about this is using GlideAjax. Pass in the catalog item name or sys_id, check to see it is an order guide, and if so, then hide the fields.
Script include:
getCatItemName : function() {
var cgr = new GlideRecord('sc_cat_item');
var catItemID = this.getParameter('sysparm_cat_item_id');
//gs.log("TM===> Getting name for " + catItemID, "Q: getCatItemName Ajax");
if(cgr.get(catItemID)){
return cgr.name;
}
}
Catalog client script (onLoad, 'Both' UI Type, applies to 'Catalog Item):
function onLoad() {
/*
// Call GlideAjax
*/
var catItemID = g_form.getUniqueValue();
var ga = new GlideAjax('AjaxUtils');
ga.addParam('sysparm_name','getCatItemName');
ga.addParam('sysparm_cat_item_id', catItemID);
ga.getXML(switchLabel);
/*
// Swap the label
*/
function switchLabel(response) {
answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
if (answer == "Convert rental/RPO unit to owned") {
//alert('yes');
g_form.setLabel('unr_pi_purchase_price', 'Buyout Amount at End Date (excluding all taxes)');
}
}
}
This is an example of something I wrote to switch the label on a field depending on the catalog item loaded. As I was using variable sets across multiple items and didn't want to create a whole new one just to modify a field label. You should be able to do the same thing and return the catalog item name or type, then hide the fields based on that.
Hope that makes sense!
Cheers,
Tim

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 09:27 AM
Thanks Patrick. If it worked, could you mark my answer correct.
Thanks,
Sanjiv
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2017 02:45 AM
Hi Patrick,
Even I am trying to hide the fields of a catalog Item in a order guide. Please let me know if you have found any solution for this.
Thanks & Regards ,
Sreejith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2020 06:51 AM
Hello,
Please find the below post, it worked for me.
Thanks,
Laxmi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 03:38 AM