How to select Multiple Values in a Select Box Variable without updating ACL or in a List Collector Variable without creating a custom Table for options.

Laukik Udpikar
Tera Expert

Hello Experts,

I need to know how to select Multiple Values in a Select Box Variable without updating ACL or in a List Collector Variable without creating a custom Table for options.

I saw multiple articles which mentioned either updating an ACL or creating a custom table both are not suitable in my case. If there's any other way to achieve the same please comment you response. 

Thank you.

1 ACCEPTED SOLUTION

To prevent duplicates from being entered, you basically have to read the current value of the MRVS and loop through the rows to see if the new value has already been used.  Getting the current value of the MRVS works differently in the Service Portal, so first we need an onLoad Catalog Client Script running on the Catalog Item, not within 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;
	}
}

Now when you create an onChange Catalog Client Script within the MRVS when Vulnerability Type changes, it will be able to get the value of the already-submitted rows in both Service Portal and the native UI.

 
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var mrvs = '';
    if (this) { //Service Portal method
        mrvs = this.cat_g_form.getValue('mrvs_internal_name'); //internal name of your MRVS
    } else { //native UI method
        mrvs = parent.g_form.getValue('mrvs_internal_name');
    }
	if(mrvs.length>2){//native UI empty MRVS = '[]'
		var obj = JSON.parse(mrvs);
		for (var i = 0; i < obj.length; i++) {
			if(obj[i].vulnerability_type == newValue){//replace with your variable name
				g_form.clearValue('vulnerability_type');
				alert('Vulnerability Type already exists in this table.');
			}
		}
	}
}

You can add an alert on mrvs to show the JSON formatting of the MRVS value.  It's a little easier to work with MRVS values in server script, so if you have later requirements needing to do something with the contents of the MRVS, try to do it in a workflow Run Script or Business Rule.  The idea is similar to what's shown in the onChange script, but you don't need to parse it.  So to get the value and loop through the elements would be something like this.

var mrvs = current.variables.mrvs_internal_name;
var rowCount = mrvs.getRowCount();
for(var i=0; i<rowCount; i++){
  var row = mrvs.getRow(i);
  gs.info('This is the value of the variable in row ' + i + ': ' + row.vulnerability_type); 
}

You can also add rows or update values with this same approach.  More than you need to do on this project, but good to keep in mind for future use.

View solution in original post

15 REPLIES 15

Hey Brad,

 

I was thinking of a variable as below : vulnerability type ( for others)

When MVRS has 'other' selected the 2nd variable should be visible and mandatory.

 

When I add the variable to the MVRS it comes up as a new column which I don't want.

And if I put the Catalog UI policy on Catalog Item the condition doesn't work. Any ideas?

find_real_file.png

Vulnerability Type (for others) is a variable in the MRVS, but shows up outside of it?  I have not seen that happen before.  You can make a variable in an MRVS mandatory or read only, but not hidden - until Quebec.  So if you delete this variable and re-create it, or whatever you need to do to get it to show up beside Vulnerability Type, you can make it read only unless Vulnerability Type is Other, then when you upgrade to Quebec there will be an option to hide the variable, the same way as variables outside of an MRVS I would imagine.

Hey Brad,

Sorry for the confusion, I've created the variable outside of the MVRS, i.e as a separate variable on the catalog item. I want it to be only visible and mandatory when I select 'others' in the MVRS.

If I create the variable inside the MVRS it just takes up space and it not useful for the other 20 types that I have.

Thanks for the info on Quebec. I'm currently on Paris, if needed I'll make this change after our upgrade to Quebec.

Oh, that makes more sense.  You'll want a Catalog UI Policy on the Catalog Item, not within the MRVS to initially hide the new variable, or else an onLoad Catalog Client Script on the Catalog Item if this next script doesn't override the UI Policy.  Then you'll need an onSubmit Catalog Client Script within the MRVS.

function onSubmit() {
    var mrvs = '';
    if (this) { //Service Portal method
        mrvs = this.cat_g_form.getValue('mrvs_internal_name'); //internal name of your MRVS
    } else { //native UI method
        mrvs = parent.g_form.getValue('mrvs_internal_name');
    }
    if (mrvs.length > 2) { //native UI empty MRVS = '[]'
        var obj = JSON.parse(mrvs);
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].vulnerability_type == 'Others') { //replace with your variable name
                if (this) {
                    this.cat_g_form.setDisplay('variable_name', true); //replace with your variable name
                } else {
                    parent.g_form.setDisplay('variable_name', true);
                }
            }
        }
    }
}                         

Hi Brad, the above link doesn't work anymore - can you point me to a location where I can find the solution?