The CreatorCon Call for Content is officially open! Get started here.

Hide a single variable in a variable set

Teri Bobst
Mega Guru

I have a variable set: Contact Info that is applied to every item in my service catalog. I have a variable within this set called Ship_to. I only want Ship_to to be visible and mandatory if the items billable(sc_cat_item_billable) flag is true.

I have tried multiple client scripts and UI policies but have not gotten any to work yet. Has anyone been able to accomplish this before?

Thanks,

Teri

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

This may sound a little odd, but it works.   I'm assuming here that "Ship_to" is visible and mandatory by default.



1. Create a new Variable Set called "Hide Ship To" (or whatever)


2. Create a new "onLoad" Client Script with the following settings:



Applies to:             Variable Set


Variable set:       Hide Ship To


Applies on a Catalog Item view:         checked


Applies on Requested Items:                   checked


Applies on Catalog Tasks:                               checked


Script:


function onLoad() {


      try{


                  g_form.setMandatory("variables.Ship_to", false);


                  g_form.setDisplay("variables.Ship_to", false);


      } catch(err) {}


}



Add the new Variable Set to each Catalog Item where you want the field hidden.   No actual Variables are required in the Variable Set.  


View solution in original post

5 REPLIES 5

Michael Fry1
Kilo Patron

Sounds like a Catalog UI Policy should work in this case. When you tried Catalog UI, what happened? Can you attach a screen shot?


TJW2
Mega Guru

I have found that the 'Show Related Fields' does NOT work in the condition fields on UI Policies.



A work around until SNow gets the 'Show Related Fields' to work is as follows:


Use a catalog Client Script - OnLoad


Get the item Sys_id using - var sys_id = g_form.getParameter("sysparm_id");


Call Script Include to get the catalog Item billable field


Use g_form.setDisplay() to display field when required.


Jim Coyne
Kilo Patron

This may sound a little odd, but it works.   I'm assuming here that "Ship_to" is visible and mandatory by default.



1. Create a new Variable Set called "Hide Ship To" (or whatever)


2. Create a new "onLoad" Client Script with the following settings:



Applies to:             Variable Set


Variable set:       Hide Ship To


Applies on a Catalog Item view:         checked


Applies on Requested Items:                   checked


Applies on Catalog Tasks:                               checked


Script:


function onLoad() {


      try{


                  g_form.setMandatory("variables.Ship_to", false);


                  g_form.setDisplay("variables.Ship_to", false);


      } catch(err) {}


}



Add the new Variable Set to each Catalog Item where you want the field hidden.   No actual Variables are required in the Variable Set.  


Hi Jim, this was a perfectly simple and brilliant solution! It worked like a charm...I just wished I had asked prior to trying a hundred different ways to get this to work... I would have never thought of this solution.



Thank you!!


Teri