Show/Hide variable in MRVS based on variable change out of MRVS

Dennis17
Tera Guru

Hi guys,

I'm struggling  to achieve the following: based on a variable value change (select box variable) in a catalog item (located directly on the catalog item), I need to display or hide another variable inside of one MRVS.

Is that possible?

 

Thanks in advance!

1 ACCEPTED SOLUTION

Rishi_11
Kilo Sage

Hi @Dennis17 ,

Try creating a duplicate hidden (select box) variable in the MRVS. Use a onLoad client script(in the MRVS) to populate its value in the MRVS. Once this is done you can use UI policies on the MRVS to conditionally show the fields. Sharing onLoad script for your reference.

function onLoad() {
    //Type appropriate comment here, and begin script below
    var type = g_service_catalog.parent.getValue("Variable on the catalog item"); //replace with variable on the catalog item
    g_form.setValue("Variable on the MRVS", type); //replace with variable on MRVS
}

This has worked for me in the past. Hope this helps.

 

Please mark this response as correct or helpful if it assisted you with your question.

Thanks,

Rishi.

View solution in original post

6 REPLIES 6

Hi @Rishi_11 ,

Sorry for the previous comment but your solution works perfectly!

Thanks a lot!

Ankur Bawiskar
Tera Patron
Tera Patron

@Dennis17 

there is a trick to access outside variable within onLoad or onChange catalog client script which applies on MRVS

You can access the outside variable using this syntax, it works in both native + portal

var variableValue = g_service_catalog.parent.getValue("outsideVariableName");

I wrote a 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