hiding variables on order guide

patricklatella
Mega Sage

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

}

   

}

find_real_file.png

1 ACCEPTED SOLUTION

Community Alums
Not applicable

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



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


View solution in original post

23 REPLIES 23

patricklatella
Mega Sage

Hi Tim,


these are variables on various catalog items that I'm including in an order guide.   They are not part of a variable set...so each catalog item has a variable or 2 that I don't need the user the see if the catalog item is being viewed in an order guide.



This is not in ServicePortal and I'm wondering if that is the issue.


In your client script, You also need to mark it Applies on Requested Item and Applies on Catalog Tasks as well.



Please mark this response as correct or helpful if it assisted you with your question.

patricklatella
Mega Sage

Hi Sanjiv,


thanks for the reply...so I checked those boxes and the variables are still showing on my order guide, and I'm not seeing the alert.



find_real_file.png



find_real_file.png


isOrderGuide() wont work on RITM. Why are you checking isOrderGuide(). If you remove that statement, it will work.



Please mark this response as correct or helpful if it assisted you with your question.

patricklatella
Mega Sage

thanks Tim,


I'll check out using GlideAjax