Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Hide variables for specific order guide

Community Alums
Not applicable

Hello,

We have 2 order guides where for specific items they need to show/remove specific fields. I've created a client script but need to specify an actual order guide however doesnt seem to be working. Any help would be appreciated.

function onLoad() {
var isOG = g_service_catalog.isOrderGuide(); //Checks if order guide
if(!isOG && g_form.getValue('95d3b7a9974ed150b34b7a671153af55')){ //checks for specific order guide
	
	g_form.setDisplay('business_justification', false); //if yes - Doesnt show field
}else{
	g_form.setDisplay('business_justification', true); // if no - Shows field.
	
}
}
1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi

Try this updated scripts -

 

For native  UI- get sysparm_guide

For portal UI - get sys_id

 

Note - Isolate Script field is set to false for this client script.

 

function onLoad() {
	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);


	var isOG = g_service_catalog.isOrderGuide(); //Checks if order guide
	if (orderGuideSysId == 'add_sys_id_here') { //checks for specific order guide

		g_form.setDisplay('business_justification', false); //if yes - Doesnt show field
	} else {
		g_form.setDisplay('business_justification', true); // if no - Shows field.
	}

}

 

 

Thanks,

Sagar Pagar

The world works with ServiceNow

View solution in original post

2 REPLIES 2

Sagar Pagar
Tera Patron

Hi

Try this updated scripts -

 

For native  UI- get sysparm_guide

For portal UI - get sys_id

 

Note - Isolate Script field is set to false for this client script.

 

function onLoad() {
	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);


	var isOG = g_service_catalog.isOrderGuide(); //Checks if order guide
	if (orderGuideSysId == 'add_sys_id_here') { //checks for specific order guide

		g_form.setDisplay('business_justification', false); //if yes - Doesnt show field
	} else {
		g_form.setDisplay('business_justification', true); // if no - Shows field.
	}

}

 

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Community Alums
Not applicable

Amazing! Thank you.