MRVS

pk2184046
Tera Expert

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.

 

1 ACCEPTED SOLUTION

AakashG0904
Tera Expert

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);
	}
}

 

AakashG0904_5-1712763573898.png

Output: -

AakashG0904_6-1712763960279.png

AakashG0904_7-1712763983591.png

 

Catalog UI Policy: - Use Case - Hide Short Description Field if a Caller Field is Empty.

AakashG0904_8-1712764952096.png

AakashG0904_9-1712764974909.png

Output: -

AakashG0904_10-1712765328586.png

AakashG0904_11-1712765341315.png

 

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

View solution in original post

7 REPLIES 7

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

pk2184046
Tera Expert

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.

1234av
Tera Contributor

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