Is there a better way (explanation below) to remove an option in a new MRVS row if already selected?

Lon Landry4
Mega Sage

Explanation of question:

(Stop selected items from being selectable)

Initial list displayed to user. Note: Row content is unique.

1st row

Apple

red

2nd row

Banana

yellow

3rd row

Orange

orange


A User selects a row. Example 1st Row (Apple).

If the user adds another row to MRVS, the previous selection needs to be filtered from the list.

Example

1st  row

Banana

yellow

2nd row

Orange

orange

 

The only way I know of to get to the values in a MRVS after row is submitted; is to create a placeholder variable on the form that is populated with value from MRVS allowing access to the value from the form. So, then I add the value from form to an advanced reference qualifier to filter out the previously selected value.

 

Is there another way to accomplish removing an option in a new MRVS row if already selected?

3 REPLIES 3

Nick Parsons
Mega Sage

Can you please clarify what you mean by "selected" here? A user can click the pencil icon to edit an existing row which then shows a popup, where they can close the popup or click "submit". Is this what you mean by "selecting"? Have they still "selected" the row if they opened the row via the pencil icon but closed the popup without clicking submit (is that still considered a "selection" in your view?). 

James Chun
Kilo Patron

Hey @Lon Landry4,

 

Found this great solution by @Rob Humphries on the thread - https://www.servicenow.com/community/itsm-forum/reference-qualifier-on-catalog-multirow-variable/m-p...

 

Modified the script slightly to meet your requirements:

 

Variable reference qualifier:

javascript: 'sys_idNOT IN' + session.getClientData('prop_name');

 

onChange client script on the variable:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ga = new GlideAjax("MRVSDependencyHelperAjax");
    ga.addParam("sysparm_name", "setClientDataForMRVSRefQual");
    ga.addParam("sysparm_prop", "prop_name"); //change this to be more descriptive
    ga.addParam("sysparm_val", newValue);
    ga.getXMLAnswer(function(answer) {
        return;
    });
}

 

Script Include (client callable)

var MRVSDependencyHelperAjax = Class.create();
MRVSDependencyHelperAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    /*Description - Add a property to session client data
     * param - prop string - the property name to add
     * param-  val string - the value of the property to add
     * returns - n/a no return value
     */
    setClientDataForMRVSRefQual: function() {
        var prop = this.getParameter("sysparm_prop");
        var val = this.getParameter("sysparm_val");

        var session = gs.getSession();
		session.putClientData(prop, val);
        return;

    },

});​

 

A few things to note:

  • Feel free to change the names (e.g script include, session client data, etc)
  • The above script will overwrite the session client data on every change. For your use case, you would need to modify the script such that it will append/update the list of selected incidents as users can select multiple records.

 

Hope that helps, cheers

 

Lon Landry4
Mega Sage

So far, not working.
I am going to take another pass tonight and will post error messages.
I remember one of the message was about using a deprecated feature.