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

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

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.

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   
   var choice_type = parent.g_form.getValue('this_inquiry');
   alert('choice_type'+choice_type);
   
   if(choice_type == 'new_server')
   {  
     g_form.setDisplay('origin',true);
   
   }    
 
here i am make field called origin (choice field ) visible when you select new_server choice type
in the field called 'this_inquiry'.
 
but its not working 
can you please help !!
 
 
 

Hi @tushar_ghadage 

Use the below script and try

unction onLoad() {
   //Type appropriate comment here, and begin script below
   
   var choice_type = g_service_catalog.parent.getValue('this_inquiry');
   alert('choice_type'+choice_type);
   
   if(choice_type == 'new_server')
   {  
     g_form.setDisplay('origin',true);
   
   }    

pk2184046
Tera Expert

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