- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 07:16 AM
How to hide the fields in the mrvs using client scripts
Recently I got to know about
g_form.getValue(g_form.getDisplayBox('field_name’).id)
Not sure how it works.
and also how to get/set values field values which are outside the mrvs to set those field values to MRVS vice versa.
Solved! Go to Solution.
- Labels:
-
Employee Service Center
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 09:09 AM - edited 04-12-2024 06:26 AM
Hi @pk2184046,
Hope you are doing well.
Proposed Solution
Q - How to hide the fields in the mrvs using client scripts?
A - As a solution, you can hide/show the fields of an MRVS using "Catalog Client Script" as well as "Catalog UI Policy". You just need to create any one of the two and Applies to "Catalog Item/Variable Set" depending on the requirement and condition you will have. Attaching scripts and snapshots for the reference.
On-Change Catalog Client Script: - Use Case - Hide Short Description Field if Logged-In User != Current user
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue != g_user.userID) {
g_form.setMandatory('u_short_description', false);
g_form.setDisplay('u_short_description', false);
}
else{
g_form.setMandatory('u_short_description', true);
g_form.setDisplay('u_short_description', true);
}
}
Output: -
Catalog UI Policy: - Use Case - Hide Short Description Field if a Caller Field is Empty.
Output: -
If you find this information/knowledge/solution as helpful, please do not forget to mark the same as Helpful and Accepted as a Solution.
Thanks
Aakash Garg
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 09:46 PM - edited 04-12-2024 06:26 AM
Hi @pk2184046,
Hope you are doing well.
The solution will remains same irrespective of any field whether you will use Reference, Lookup, and Select Box or any other Variable. FYI, please have a look at once deeply to my Previous Proposed Answer to your question where I have used Reference Field as a Caller and based on this field, hiding another field [Short Description] using both Client Script and UI Policy. Hope you will be able to get it now.
If you find any of the information/knowledge/solution shared as helpful, please do not forget to mark the same as Helpful and Accepted as a Solution.
Thanks
Aakash Garg
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 08:16 AM
Hi there,
Thanks for sharing the information to hide variables inside the MRVS.
Can you please explain the same if the variable in the MRVS to be hidden outside the variable set at form level
considering the variable as reference field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2024 11:07 AM
Multi-row variable set accepts an array for JSON and you can use g_form.setValue to set the value
g_form.setValue('mlv','[{"ets":"val1"},{"ets":"val2"}]') // mlv - variable set name, ets - variable name, val1 and val2 are the 2 values that i am assigning vai the client script