Display a variable based on criteria in a multirow table

CatalogCat
Tera Contributor

I am working on a catalog item where I want to display a rich text label based on a condition inside a multirow table. 

If the text string "External" is added to a single text variable inside the multirow, then my rich text label should be visible. If the text input is any other than "External" the rich text label should not be visible.

 

I might add that the single text variable is autopopulated from a user record and will always contain either the text "External" or "Employee". The rich text label is not relevant if the single text is populated with "Employee"

 

Is this possible? 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@CatalogCat 

you can access MRVS variable and get the variable value

But when should this be checked? what's the trigger for this?

Is it when a row is added or removed?

if yes then check this link which tells you how to detect row is added/removed and then based on the JSON string of MRVS you can show/hide the outside variable

MRVS detect when a row is removed or deleted 

Widget that reacts to onChange event of Variable 

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

Brad Bowman
Kilo Patron
Kilo Patron

Sure.  Since rich text label variable can't be part of a MRVS, how do you want to handle the condition where one row of the MRVS is populated with External, then another is populated with Employee, or vice-versa?  Is the MRVS variable auto-populated on request form load, or onChange of a variable, or when a row is manually added to the MRVS?

CatalogCat
Tera Contributor

The MRVS variable is auto-populated by another variable on the same row, through an On-change script. The other variable is a Reference to the Users table. The User record has a text attribute that will always be Employee or External. I would like my Rich text label to appear when I have finished adding a row to the table, if the criteria is met.

You can use a Catalog Client Script like this, that applies to the MRVS, when the single text variable changes, or onSubmit (when a row is added or edited).

function onSubmit() {
    if (g_form.getValue('v_text') == 'External') { //MRVS text variable name
  	    if (this) { //Service Portal method
		    this.cat_g_form.setDisplay('v_label', true);
	    } else { //native UI method
		    parent.g_form.setDisplay('v_label', true);
	    }
    } else {
        if (this) { //Service Portal method
		    this.cat_g_form.setDisplay('v_label', false);
	    } else { //native UI method
		    parent.g_form.setDisplay('v_label', false);
	    }
    }
}

If you are using Service Portal, ESC,... you will also need this 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;
	}
}