Limit MRVS reference field by same field on other rows?

Shane J
Tera Guru

Trying to determine if it's possible to setup an advanced reference qualifier to restrict a MRVS (Multi-Row Variable Sets) reference variable by other rows already entered?

 

I'm using a MRVS to allow a user to pull records from a custom inventory table, and in a perfect world they shouldn't be able to pick the same record already chosen in a previous row.

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

This is not a reference qualifier, but you can run a script like this onChange of the reference variable to clear it if it already exists in the MRVS:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var mrvs = g_service_catalog.parent.getValue('mrvs_internal_name'); //internal name of your MRVS
    if (mrvs.length>2) { //native UI empty MRVS = '[]'
        var obj = JSON.parse(mrvs);
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].var_name == newValue) { //replace with your variable name
                g_form.clearValue('var_name');
                alert('User already exists on a row.');
			}
		}
	}
}

 Now I'm wondering if this logic would would work in a reference qualifier - calling a Script Include, passing in the value of the (existing) MRVS, then the SI queries whatever is already in your reference qualifier, excluding any existing values to return the list of sys_ids.  It could work.

This would work as is in most cases I'd guess, but of course in this case the user can:

-Choose a single record OR

-Choose a single record, but has the option to then say include all with the same TYPE

I'll have to try the Script Includes route.

I just remembered why reference qualifiers can't pass in the existing MRVS value - it uses the current.variable_name format, not g_form/g_service_catalog.parent, and the MRVS can't be accessed via current.*

I was thinking I could just use your solution if I went ahead and added the Rows for the 'matching by TYPE' records but that would require some other rework.  

 

At this point, I'm going to see if the stakeholder is fine with what's there.