Need to make MVRS readonly based on variable selection

Abdul
Tera Contributor

I have a variable named Purchase type which has like 4 values and when i select one value which is Refinery Request, then a bunch of variables which are declared under variable set MRVS, like Quantity, Asset number. They all should be made read only and non mandatory.
I tried to use UI policy but it is not working

Please suggest.

 

Thanks  

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Abdul 

you can write onLoad catalog client script on MRVS and then use this logic
Note: I assume your purchase type variable is outside MRVS

function onLoad() {
	
    var variableValue = g_service_catalog.parent.getValue("purchaseTypeVariableName");

    // give correct value to compare here
    if (variableValue == 'Refinery Request') {
        // make your mrvs variables read only and non mandatory here

    }

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Bhimashankar H
Mega Sage

Hi @Abdul ,

 

In your existing UI policy add below two lines of code.

function onCondition() {
    var my_var = g_form.getField("MRVS_Name");//use your variable set name here
    g_form.setReadOnly('MRVS_Name',true);
}

 

This will make the variable set read-only and hide the edit/delete/add and remove all buttons.

 

For you want to do more customization refer this.

MRVS - Button Policies 

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!

Ankur Bawiskar
Tera Patron
Tera Patron

@Abdul 

you can write onLoad catalog client script on MRVS and then use this logic
Note: I assume your purchase type variable is outside MRVS

function onLoad() {
	
    var variableValue = g_service_catalog.parent.getValue("purchaseTypeVariableName");

    // give correct value to compare here
    if (variableValue == 'Refinery Request') {
        // make your mrvs variables read only and non mandatory here

    }

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Abdul 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader