Hiding a multi row variable set variable reference option

Amina El hadad
Tera Contributor

Hello everyone,

I have a catalog item that includes a Multi-Row Variable Set (MRVS) named "new_tables", which contains a variable called "table". This variable is a reference to the sys_db_object table.

I want to ensure that users cannot select the same table more than once.

For example, if a user selects ".NET Application" in the first row, it should no longer be available for selection when adding a new row.

Any thoughts?

Thank you.

3 ACCEPTED SOLUTIONS

Hi @Amina El hadad ,

try this

try to alert newTables and see what you are getting

function onSubmit() {

    var newTables = g_service_catalog.parent.getValue('new_tables');
    newTables = newTables ? newTables : '[]';
    var systemTabs = JSON.parse(newTables);
    for (var i = 0; i < systemTabs.length; i++) {
        if (systemTabs[i]['table'] == g_form.getValue('table')) {
            g_form.addErrorMessage('table is already added');
            return false;
        }
    }
}

 

if you still getting the error 

 

Could you please share the screenshots of the error and the configuration that you have done and the MVRS and it's scripts?

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

Medi C
Giga Sage

Hi @Amina El hadad,

 

I hope you are doing well! I was able to solve your issue on my PDI. Please follow below instructions to get a working solution:

 

  1. Go to your Multi-Row Variable Set "new_tables"
  2. Create OnSubmit Catalog Client Script with the following script: (Please ensure variable names are correct)
function onSubmit() {
    var multiRow = JSON.parse(parent.g_form.getValue("new_tables")); 

    var obj = {
        'table': g_form.getValue('table')
    };

    if (multiRow) {
        var result = multiRow.filter(function(item) {
            return (item.table == obj.table);
        });
        if (result.length > 0) {
            g_form.addErrorMessage('You have entered the same twice');
            return false;
        }
    }
}

 

Results:

As you can see below screenshot, I was unable to add ".NET Application" twice. the Error message would be displayed when you click on Add.

 

MediC_0-1741972637496.png

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

View solution in original post

Hi @Amina El hadad,

 

Yes! that is definitely possible. Please follow below instructions to achieve your requirements:

 

1- Disable/Deactivate Existing Catalog Client Script(s) you created earlier in the previous solution(s)

 

2- Create OnLoad Catalog Client Script on your Variable Set

 

function onLoad() {
    var catItemVarName = 'community_test'; //PLEASE REPLACE THIS WITH YOUR VARIABLE SET TECHNICAL NAME
    var catItemVarValue = g_service_catalog.parent.getValue(catItemVarName);
    var ga = new GlideAjax('RefQualifierClient'); // PLEASE USE THE SCRIPT INCLUDE WHICH IS CREATED IN NEXT STEP
    ga.addParam('sysparm_name', 'setSessionData'); //function in script include
    ga.addParam('sysparm_cat_item_var_name', catItemVarName);
    ga.addParam('sysparm_cat_item_var_value', catItemVarValue);
    ga.getXMLAnswer(getResponse);
}

function getResponse(response) {
    //do nothing 
}

 

 

3- Create a Script Include (Client Callable / Glide AJAX enabled) - In my example, I named it "RefQualifierClient"

 

4- Add the following function to your script include:

 

    setSessionData: function() {
        var sysId = [];
        var catItemVarName = this.getParameter('sysparm_cat_item_var_name');
        var catItemVarValue = this.getParameter('sysparm_cat_item_var_value');
        var variableSetData = JSON.parse(catItemVarValue);
        for (var i = 0; i < variableSetData.length; i++) {
            sysId.push(variableSetData[i].table); //REPLACE "table" WITH TECHNICAL NAME OF THE REFERENCE FIELD TO sys_db_object ON YOUR VARIABLE SET
        }
        var session = gs.getSession().putClientData(catItemVarName, sysId);
        return;
    }

 

MediC_0-1742004398617.png

 

5 - Go to your reference variable to sys_db_object on your Variable Set. And set an advanced Reference qualifier as follow:

 

javascript&colon; "sys_idNOT IN" + session.getClientData("community_test"); // REPLACE community_test WITH YOUR VARIABLE SET TECHNICAL NAME

 

 

MediC_1-1742004499801.png

 

(Please follow the comments on the give script where you need to update some input with your variable / script include names)

 

I tested it on my PDI and it is working as expected. Selected tables are no longer displayed when adding a new row.

 

MediC_2-1742004846897.png

 

I hope it helps!

 

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

View solution in original post

11 REPLIES 11

Hi @Chaitanya ILCR

Yes I added the script to the MRVS, and "new_tables" is the internal name of the MRVS

 

Hi @Amina El hadad ,

try this

try to alert newTables and see what you are getting

function onSubmit() {

    var newTables = g_service_catalog.parent.getValue('new_tables');
    newTables = newTables ? newTables : '[]';
    var systemTabs = JSON.parse(newTables);
    for (var i = 0; i < systemTabs.length; i++) {
        if (systemTabs[i]['table'] == g_form.getValue('table')) {
            g_form.addErrorMessage('table is already added');
            return false;
        }
    }
}

 

if you still getting the error 

 

Could you please share the screenshots of the error and the configuration that you have done and the MVRS and it's scripts?

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Hi @Chaitanya ILCR,

It’s working now! Thank you for your help, I really appreciate it!

 

Medi C
Giga Sage

Hi @Amina El hadad,

 

I hope you are doing well! I was able to solve your issue on my PDI. Please follow below instructions to get a working solution:

 

  1. Go to your Multi-Row Variable Set "new_tables"
  2. Create OnSubmit Catalog Client Script with the following script: (Please ensure variable names are correct)
function onSubmit() {
    var multiRow = JSON.parse(parent.g_form.getValue("new_tables")); 

    var obj = {
        'table': g_form.getValue('table')
    };

    if (multiRow) {
        var result = multiRow.filter(function(item) {
            return (item.table == obj.table);
        });
        if (result.length > 0) {
            g_form.addErrorMessage('You have entered the same twice');
            return false;
        }
    }
}

 

Results:

As you can see below screenshot, I was unable to add ".NET Application" twice. the Error message would be displayed when you click on Add.

 

MediC_0-1741972637496.png

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Hi @Medi C,

Thank you a lot, I appreciate really your support!

Would you be able to help with hiding the table option once it has been selected, so it is no longer available for selection again instead of showing the error message?