How to make variables only visible on specific catalog task

sacha2
Kilo Contributor

Hi,

My question seems pretty basic I guess but I need to be able to display some variables only on specific catalog tasks.

I guess I'll have to deal with catalog UI policies but I don't know where to start with this.

For example, in one catalog task I want to have this question "Do you validate the quote ?", but only in this particular CT, not anywhere else.

Is there a specific javascript chunk of code to write or it's simpler than that ?

Thanks.

1 ACCEPTED SOLUTION

Hi,

While creating Catalog Task from workflow you can ensure you show only the variables you want to be visible.

This can be done by selecting variables from Available to Selected section

OR

Sample script below if those variables are present on more than 1 task and you want to show only for 1

function onLoad() {
	//Type appropriate comment here, and begin script below

	var shortDescription = 'Your Task Short Description for which it needs to be visible';
	if(g_form.getValue('short_description') != shortDescription){
		
		// if that variable is mandatory then make it non-mandatory first
		
		g_form.setDisplay('variableNane', false);
	}

}

Regards
Ankur

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

View solution in original post

8 REPLIES 8

So you mean that I can know on which catalog task I'm at based on the description ? how about the name ?

Why checking that "the task short description is not your specific task description" ?

Do you have a script example to hide a variable ?

Hi,

Example: for RITM001 you have 3 Tasks

SCTASK001, SCTASK002, SCTASK003

Each have unique short description

You want to show variable ABC only for SCTASK002 and not for SCTASK003

So the above script you will give the unique short description of SCTASK002 so that when it doesn't match it would hide that variable ABC i.e. hide it for SCTASK001 and SCTASK003

Hope you got an idea

Regards
Ankur

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

Hi @Ankur Bawiskar,

 

According to your answer we can create either catalog client script or UI policy to handle the visibility of variables but here my question is how can we access the SC Task short description or description field in condition check field of UI policy.

 

AnkurKasana_0-1726222724462.png

 

We can only access the variables values. Waiting for you answer

 

I would like to ask one more question here when we create any catalog client script and apply on task record or select any other available choice, then what value we can fetch by using g_form on variables value or record field value as well. Please answer

 

Thank you 

Aman Singh_
Kilo Sage

Hi

If You want the variable to be available only at the Catalog Task then make sure you uncheck the highlighted and checked the remaining two either in UI Policy/Client Script

 

 

Please mark Correct✅/helpful if applicable, thanks!!

Aman