We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Limiting additional data for variable sets

bonsai
Mega Sage

 

I added a variable set to a catalog item.
I don't think there's a limit to the number of pieces of data that can be added to this variable set.
However, I would like to limit the number of pieces of data that can be registered to 10.

Is it possible to set a limit on the number of pieces of data that can be added to a variable set?
I'm considering disabling the addition of the 11th piece of data and making it an error, but I can't think of a good way to do this.

test_item.png

1 REPLY 1

AnirudhKumar
Mega Sage

You will have to script this, unfortunately.

 

1. Create an onLoad client script on the catalog item level:

function onLoad() {
    GLOBAL_VAR = {
        g_form: g_form
    };
}

 

 

2. Create an onSubmit client script at the variable set level:

function onSubmit() {

    var numberOfAllowedRows = 2;//Pick depending on your validation
    var mrvs = GLOBAL_VAR.g_form.getValue('your_variable_set_name').toString();
    if (mrvs) {
        if (JSON.parse(mrvs).length == numberOfAllowedRows) {
            alert('Only ' + numberOfAllowedRows + ' rows allowed');
			return false;
        }
    }

}

 

Note :

The variable set name you will need to use in the second script is the internal name of the variable set.

Set the UI Type to All on both the client scripts so they run on portal