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

Patrick,


I found this article on the wiki and it worked for me.


Hide cascaded variables



Syntax looks like this.



if(g_service_catalog.isOrderGuide()){


  g_form.setDisplay('variable_name', false);


}


patricklatella
Mega Sage

yes, when it is a catalog item the user will fill in the details.



When it is on the name item but in the order guide, the user will fill in the matching fields on the first page of the order guide and then I don't need the variables to show on the item.   I do want them to appear on the requested item, so I cannot just un-check the order guide availability box.


If the user fills in the values in first page of order guide, the same value will be passed on to catalog item.


Then we shouldn't hide those fields on RITM. It will have values from order guide.



But if you are not populating those two field from order guide, you can write another onLoad client Script to run only on Requested item to hide these variables when they are empty.



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

patricklatella
Mega Sage

sorry typo in last comment.  



When it is on the "same" item...


patricklatella
Mega Sage

awesome, thanks Sanjiv!