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

Anshula Awasthi
Giga Contributor

Hi @Brad Bowman  ,

But here how to multiselect the values from dropdown?