How do I make Catalog client script run only on Catalog item form and not when in Order guide ?

Supreeth R
Kilo Contributor

Hello,

There is a catalog client script written on a variable set that I've created on. And, have used the variable set in the catalog item as well as in the order guide. 

Now the actual requirement is, I want the catalog client script to run only on the standalone catalog item form having the variable set and not on the order guide form (even if the order guide has that particular item in it) .

Could someone help me achieve this, please ? Thanks in Advance!!

 

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

Can you try this for native UI:

$("sysparm_guide").value

 

for example:

if($("sysparm_guide").value){
		return;
	}

 

based on:

https://community.servicenow.com/community?id=community_question&sys_id=a3555ddddb36e3409540e15b8a96...

 

Or try:

g_request.getParameter('sysparm_guide')

 

Example:

if(g_request.getParameter('sysparm_guide')){
		return;
	}

 

Based on:

https://community.servicenow.com/community?id=community_question&sys_id=7c350f6ddbd8dbc01dcaf3231f96...

View solution in original post

6 REPLIES 6

Anurag Tripathi
Mega Patron
Mega Patron

HI,

if this is part of portal then you can use the below

g_service_catalog

The g_service_catalog global is only available in Service Portal service catalog item scripts. Use this API to know if your catalog item script is being run as part of an order guide or on its own.
 function onLoad() {
   if (window) // if CMS don't run this
    return;

    // g_service_catalog api for Service Portal and Mobile
    var isOrderGuide = g_service_catalog.isOrderGuide();
    g_form.setValue("is_order_guide", isOrderGuide ? "Yes!" : "Nope :(");
}


-Anurag
-Anurag

Hello @Anurag Tripathi,

 

Thanks a lot!

This is working absolutely fine for me in the Portal. However, I'd also need a way to achieve this in the Main UI page (UI type - Desktop, Service Portal and All) of ServiceNow.

If there's a way out for this, Could you paste me your code for both Portal and Main UI page ?

Can't thing of a smart way on native ui.

May be you can keep some hidden variable(on the catalog) that will be true or false depending whether or not this catalog is part of order guide or not.

 

-Anurag

Willem
Giga Sage
Giga Sage

Few additions to Anurag's comment.

Instead of if(window) return set the UI Type to Mobile/Service Portal.

 

To not run the script for order guides use the g_service_catalog like this at the start of your script:

if(g_service_catalog.isOrderGuide()){
		return;
	}

So not set a value. But return, which stops the script from further executing.

 

Please reference below for the g_service_catalog.isOrderGuide():

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/build/service-portal/concept/uns...