The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Can we apply reference qualifier to a variable which is inside the MRVS ?

mehulaaa
Tera Contributor

I have two fields of the same table 1 is in the MRVS and another one is outside on the main catalog item form 
the one which is inside the MRVS is depended on the one which is outside 
Outside var name - Model Type number 
Inside var name - Cost Codes which are associated with the model type
kindly suggest me any solutions on how do I populate cost codes based on model type?

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

You can (currently) only use variables in the MRVS in a reference qualifier in the MRVS.  A workaround I have used in this scenario is to create an additional variable in the MRVS (named model_type_mrvs in this example) that matches the type of variable as the one outside the MRVS (named model_type in this example).  Then create an onLoad Catalog Client Script that applies to the MRVS.  This script will populate the new variable in the MRVS with the value from the variable outside the MRVS.  You can also add a line to make this read only, and/or hide this variable - or try the 'hidden' checkbox on the variable definition, but just know that either method will only hide the variable on the add/edit dialog, not when the contents of the MRVS are displayed.  This is what the script would look like:

function onLoad() {
    g_form.setValue('model_type_mrvs', g_service_catalog.parent.getValue('model_type');
    g_form.setReadOnly('model_type_mrvs', true);
}

You can then use current.variables.model_type_mrvs in your reference qualifier.

 

This is a great solution, thanks for sharing!

Brad Bowman
Kilo Patron
Kilo Patron

Here's a method that does not require the creation of another MRVS variable:

https://www.servicenow.com/community/now-platform-articles/yes-you-can-effectively-set-or-update-a-r...