How to get order guid sysid using client catalog script in service portal?

Mihir YSSS
Tera Contributor

I wanted to get the sys id of the order guide using client catalog script. I have created one maintain item and added one variable of type list collector. I have added this into order guide. Same maintain item will be used in multiple order guides. I need to show or hide the option based on order guide. I have created client catalog script for this maintain item and included following snippet, but this is always giving sys id of the maintain item not the order guide's.

var currentItem = g_form.getUniqueValue();	

How to get order guide sys id in service portal?

1 ACCEPTED SOLUTION

Hi,

nope.

for both native and portal you can get the URL parameter value in the onLoad client script and get the order guide sys_id

For native URL looks like this - https://instanceName.service-now.com/com.glideapp.servicecatalog_cat_item_guide_view.do?v=1&sysparm_initial=true&sysparm_guide=6690750f4f7b4200086eeed18110c761

For portal URL looks like this - https://instanceName.service-now.com/sp?id=sc_cat_item_guide&sys_id=6690750f4f7b4200086eeed18110c761

For native - get sysparm_guide

For portal - get sys_id

function onLoad() {
	//Type appropriate comment here, and begin script below
	
	var url = top.location.href;
	var orderGuideSysId;
	if(window == null){
		// for portal
		orderGuideSysId = new URLSearchParams(url).get("sys_id");
	}
	else{
		// for native
		orderGuideSysId = new URLSearchParams(url).get("sysparm_guide");
	}
	alert(orderGuideSysId);
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Hi,

nope.

for both native and portal you can get the URL parameter value in the onLoad client script and get the order guide sys_id

For native URL looks like this - https://instanceName.service-now.com/com.glideapp.servicecatalog_cat_item_guide_view.do?v=1&sysparm_initial=true&sysparm_guide=6690750f4f7b4200086eeed18110c761

For portal URL looks like this - https://instanceName.service-now.com/sp?id=sc_cat_item_guide&sys_id=6690750f4f7b4200086eeed18110c761

For native - get sysparm_guide

For portal - get sys_id

function onLoad() {
	//Type appropriate comment here, and begin script below
	
	var url = top.location.href;
	var orderGuideSysId;
	if(window == null){
		// for portal
		orderGuideSysId = new URLSearchParams(url).get("sys_id");
	}
	else{
		// for native
		orderGuideSysId = new URLSearchParams(url).get("sysparm_guide");
	}
	alert(orderGuideSysId);
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks. Earlier i have tried same code with window.location. I didn't know that top is one of the object. Above code works. 

Hi Ankur,

Could you please let me know what is this 

var url = top.location.href;

?

I have to get sys id of 6 order guides in my on change catalog client script.

Could you please help me out.

Hi @Ankur Bawiskar ,

I have a catalog item 'mycatalogitem' and this catalog item is part of many order guides like 'x','y','z'. The category of 'x' and 'y' order guide is 'customer'

There is a task called 'mytask' in the catalog item 'mycatalogitem'.

Requirement is: when the 'state' of 'mytask' is 'closedcomplete' then there are 2 variables 'no' and 'tracking' should be mandatory when the request of the catalog item 'mycatalogitem' will be submitted through the 'customer' category order guides ('x' and 'y') only.

But if anyone raise the request for the catalog item 'mycatalogitem' using other order guides where category is not 'customer' (like 'z' order guide) or raise it seperately without using any order guide then, if  the 'state' of 'mytask' is 'closedcomplete' then those 2 variables 'no' and 'tracking' should not be mandatory.

Could you please help me out  as it is urgent.

 

Thanks in advance.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

check this link

how to identify from which order guide a catalog item is triggered?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader