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

Voona Rohila
Kilo Patron
Kilo Patron

Hi Mihir, Try this

var orderGuide = $("sysparm_guide").value;

if(orderGuide  == 'SYS_ID_OF_Order_Guide'){

//Do your logic

}

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

When I execute above script, I am seeing below error in console:

 Error while running Client Script "HideRelianceField": TypeError: $ is not a function

 

I don't see option for "Isolate Script" in catalog script script screen.

find_real_file.png

Hi,

You need to ensure

1) Isolate Script field is set to false for this client script

2) If this field is not on form then from list you can make it false

find_real_file.png

Regards
Ankur

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

I made that to false. But this will work in service portal also?