- 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: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
05-15-2025 01:14 AM
hi @AakashG0904 ,
i am doing the same thing
here is the client script iniside of MRVS to access a field which is outside of mrvs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 09:36 PM
Use the below script and try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 09:13 PM
Hi the solution is accepted if the MRVS variable is a select box.
What if the variable is a reference or a lookup variable in that it does not work correct.
Using client scripts I think it canbe achieved,by sys_id
Please provide me the solution