Solved: How can I tell if I am in an order guide? - ServiceNow Community

How can I tell if I am in an order guide?

ewilks
Giga Expert

I have a Catalog Client Script that is used by some Catalog Items and some Order Guides.   What I would like to know is if I can find out if the script is being called from within a particular order guide.  

I tried using g_form and referencing the name of the form...nope.

Is there a way that I can, through the script, find out if it's being run from within a Client Script?

Thanks,

Eric

1 ACCEPTED SOLUTION

There are a couple of hidden input fields that will help you out here.   Add the following line of code to an onLoad catalog client script on both your Order Guide and an actual Catalog Item:



g_form.addInfoMessage("sysparm_guide = " + $("sysparm_guide").value + "<br/>" + "current_item = " + $("current_item").value + "<br/>" + "on the order guide itself = " + ($("sysparm_guide").value == $("current_item").value));


It will display the sys_ids of the Order Guide (sysparm_guide) and the Catalog Item (current_item).   You will be on the Order Guide's start page if both sys_ids are the same.


View solution in original post

6 REPLIES 6

Albert13
Tera Guru

You can open the order guide and look at the related list script tab.   If it's there it's par of that guide or item.   Or edit the script and put in a gs.log("Order Guide Name"); and run your guide and see if that is put into the logs.



You might have to add the related list


screenshot.png



Albert


saritha9
Giga Expert

Class field in Catalog Item can provide you if the catalog client script is on Catalog Item or Record Producer or Order Guide.


ewilks
Giga Expert

I don't think I made it clear as to what I'm trying to do.



I have a Catalog Client Script that is run from Catalog Items and from an Order Guide.   I only want to set a field as writeable if the script is being run from a particular order guide.


For instance, in the script below, I only want to allow users with the itil_lite role and that works, but I only want this to run when it's on a particular order guide.   I have added the g_orderguide.name() which I know isn't a call, but I want to be able to find out where this code is being run before I allow the user to update a field. In this case, the code is being run from an orderguide named "Terminate" then I'll allow the user to read, if it's anything else, then set to read only.   I hope that's a little more clear.



var uRole=g_user.hasRole('itil_lite');


var isOrderGuide = g_orderguide.name();


if (isOrderGuide='Terminate'){


    if (uRole==true)


        g_form.setReadOnly('manager_name', false);


      }


      else{


        g_form.setReadOnly('manager_name', true);


      }


}


There are a couple of hidden input fields that will help you out here.   Add the following line of code to an onLoad catalog client script on both your Order Guide and an actual Catalog Item:



g_form.addInfoMessage("sysparm_guide = " + $("sysparm_guide").value + "<br/>" + "current_item = " + $("current_item").value + "<br/>" + "on the order guide itself = " + ($("sysparm_guide").value == $("current_item").value));


It will display the sys_ids of the Order Guide (sysparm_guide) and the Catalog Item (current_item).   You will be on the Order Guide's start page if both sys_ids are the same.