how to make all variables setDisplay false in a variable set in client script ?

Akki1
Tera Contributor

I want to make all variables in a variable set setDisplay false or true in a condition in client script  except one variable  in servicenow?

 

8 REPLIES 8

Hi @Akki1 ,

To find variable or field is ReadOnly in form use this method

// It returns the boolean value and it check whether variable is readonly or not
g_form.isDisabled('variable_name')  // return true or false

 

 

 

OlaN
Giga Sage
Giga Sage

Hi,

I would suggest that you create a Catalog UI policy, and add UI policy actions for this requirement.

Check out the Docs, or ask if you need additional details.

ritu_saluja
Tera Expert

@Akki1 
I would suggest make all variables setDisplay as false through client script but for 1 variable you want as true create a ui policy for that.
Mark my answer correct and helpful if it helps you

Uday_Kumar
Giga Guru

Hi @Akki1 How are you ?

Yes we can achieve this using client script on load but need to find the id of the variable. I will walk you through step by step follow me.

  1. Use your variable set in any item and console the page, use g_form.getEditableFields() to get the id of the variables and try to find your variables id using console. Actually it requires some front-end knowledge.
  2. store your id's somewhere else that you want to hide.
  3. now write the client script and store those id's in array to iterate.
  4. For every iteration make setDisplay as false.

This is the variable set i want to make changes (i want to hide all fields except the salutation variable)

Uday_Kumar_0-1679051114583.png

This is the script i wrote for every iteration the id should hide (I stored all the variables id except salutation variable so that i can achieve my requirement)

Uday_Kumar_1-1679051287493.png

The Output is here : all the fields except the salutation are hided 

Uday_Kumar_2-1679051330998.png

Please mark it as helpful and accepted if it helps you incase you need any further information feel free to ask me

Thanks and Regards

Uday Kumar Valapudasu