how to make all variables setDisplay false in a variable set in client script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 12:51 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 09:21 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 01:01 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 03:21 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 04:10 AM
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.
- 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.
- store your id's somewhere else that you want to hide.
- now write the client script and store those id's in array to iterate.
- 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)
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)
The Output is here : all the fields except the salutation are hided
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