access MRV variable in catalog variable

sravanip
Tera Contributor

Hi,

 

Each time I add row in MRV, wrote MRV client script(glideAjax) to check if the response is Yes or No.

Based on the response, if YES then I have to make variable in catalog display and mandatory true.

 

Now should I create the variable inside MRV to achieve this. But here new variables are getting created as column since its in MRV.

How to pass the response value and manipulate the variable outside MRV.

 

Thank You

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

To affect a variable outside of a MRVS, add code like this to your onSubmit Catalog Client Script that applies to the MRVS, within the response function from the GlideAjax:

if (answer == 'YES') {
    if (this) { //Service Portal method
        this.cat_g_form.setDisplay('variable_name', true);
        this.cat_g_form.setMandatory('variable_name', true);
    } else { //native UI method
        parent.g_form.setDisplay('variable_name', true);
        parent.g_form.setMandatory('variable_name', true);
} else {
    if (this) { //Service Portal method
       this.cat_g_form.setMandatory('variable_name', false);
        this.cat_g_form.setDisplay('variable_name', false);
    } else { //native UI method
        parent.g_form.setMandatory('variable_name', false);
        parent.g_form.setDisplay('variable_name', false);
    }
}

If you're not using Service Portal or similar workspaces you can simplify this by just using the parent.g_form lines.  If you are (also) using Service Portal, etc, you will need this onLoad Catalog Client Script that applies to the Catalog Item, not the MRVS:

function onLoad() {
	if (this) {//we only need to do this for Service Portal
		//We need to make the g_form object for the parent item available from the MRVS window
		this.cat_g_form = g_form;
	}
}

 

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

To affect a variable outside of a MRVS, add code like this to your onSubmit Catalog Client Script that applies to the MRVS, within the response function from the GlideAjax:

if (answer == 'YES') {
    if (this) { //Service Portal method
        this.cat_g_form.setDisplay('variable_name', true);
        this.cat_g_form.setMandatory('variable_name', true);
    } else { //native UI method
        parent.g_form.setDisplay('variable_name', true);
        parent.g_form.setMandatory('variable_name', true);
} else {
    if (this) { //Service Portal method
       this.cat_g_form.setMandatory('variable_name', false);
        this.cat_g_form.setDisplay('variable_name', false);
    } else { //native UI method
        parent.g_form.setMandatory('variable_name', false);
        parent.g_form.setDisplay('variable_name', false);
    }
}

If you're not using Service Portal or similar workspaces you can simplify this by just using the parent.g_form lines.  If you are (also) using Service Portal, etc, you will need this onLoad Catalog Client Script that applies to the Catalog Item, not the MRVS:

function onLoad() {
	if (this) {//we only need to do this for Service Portal
		//We need to make the g_form object for the parent item available from the MRVS window
		this.cat_g_form = g_form;
	}
}

 

Hi Brad,

 

Thank you for the solution. As suggested I created onload client script on catalog level and then onsubmit script in MRV. 

 

Once I add a row and submit if the response is Yes I am able to mandate the variable in the catalog level. But here the check is once the variable is made mandatory then I should not make it non mandatory even if response is 'No'.

 

If atleast one row(value) in MRV matches the criteria written in SI then make the variable in catalog level mandatory.

sravanip
Tera Contributor

Adding to it, if I add value in MRV that makes the catalog variable mandatory and then remove the MRV row then the mandatory variable should also be made non mandatory.