Make Variable in MRVS Dependent upon Field in Parent Catalog Item

jmiskey
Kilo Sage

Last month, I had a situation where I had to make a variable in a Catalog Item dependent upon a variable found in a Multi-Row Variable Set (MRVS) in the same Catalog Item (https://www.servicenow.com/community/developer-forum/make-a-catalog-item-variable-dependent-on-a-mrv...).  Now, I need to do the opposite.  I need to make a variable in my MRVS dependent upon a variable in the parent Catalog Item.

 

So, basically, in the Catalog Item, I have the following variable (among many others than do not factor into this issue):

- Type of Request (multiple choice: "Add" or "Remove")

- Who is this request for? (multiple choice: "Employee" or "External Partner")

 

And my MRVS has the following 3 fields:

- Name

- Email address

- Expiration Date

 

My MRVS is hidden, and only shows if "External Partner" is selected in the "Who is this request for?" variable.  I have no problems with any of that. 

 

But what I need to do is to make the Expiration Date field in the MRVS mandatory ONLY if the Type of Request is "Add".  I imagine that would be done with a Catalog UI Policy or Catalog Client Script within the MRVS, but I am not sure how to make it look at the "Type of Request" variable found in the parent Catalog Item.

 

Can anyone help?  Thanks

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jmiskey 

you can use onLoad catalog client script which applies to your MRVS variable set

Then use this script to access the outside variable value and then make it mandatory

Ensure you give the correct variable names and value to compare

function onLoad() {
    var requestType = g_service_catalog.parent.getValue("type_of_request");
    if (requestType == 'add')
        g_form.setMandatory('expiration_date', true);
}

I have written blog as well for this

Access value of catalog item variable within MRVS client script 

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

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@jmiskey 

you can use onLoad catalog client script which applies to your MRVS variable set

Then use this script to access the outside variable value and then make it mandatory

Ensure you give the correct variable names and value to compare

function onLoad() {
    var requestType = g_service_catalog.parent.getValue("type_of_request");
    if (requestType == 'add')
        g_form.setMandatory('expiration_date', true);
}

I have written blog as well for this

Access value of catalog item variable within MRVS client script 

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

Thank you.

That works exactly the way I need it to, and is sweet and right to the point!

J Siva
Tera Sage

Hi @jmiskey 

The g_service_catalog API provides methods to access data in a multi-row variable set (MRVS) .

For more info please find servicenow product document below.

https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_referenc...

Regards,

Siva