We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Catalog client script

vodnalar26
Tera Contributor

Hi Team,

I am trying to prevent duplicate Employee IDs from being entered in a Multi-Row Variable Set (MRVS) on a Catalog Item.

MRVS Structure

Employee ID (Single Line Text)

Employee Name

Email

Department

Example:

Employee ID

Employee Name

123

Abel Tuter

123

Abel Tuter

The same Employee ID should not be allowed more than once.

Issue

Even when I enter duplicate Employee IDs (e.g., 123 and 123), the request is submitted successfully and the validation does not trigger.

Additional information:

Employee ID is a Single Line Text variable.

The script type is Catalog Client Script – onSubmit.

The MRVS name is employee_information.

Could anyone suggest:

Whether duplicate validation on MRVS should be handled differently?

How to correctly access MRVS row values in an onSubmit Catalog Client Script?

Any known limitations with MRVS data retrieval using g_form.getValue()?

Any guidance would be appreciated.

Thank you!

2 REPLIES 2

Tejas Adhalrao
Kilo Sage

Hi @vodnalar26  ,

For MRVS duplicate validation, the important thing to remember is that the entire Multi-Row Variable Set is stored as a JSON string. The method g_form.getValue('employee_information') returns that JSON data, not the individual field values.

 

An onSubmit Catalog Client Script is the right approach, but you need to: Get the MRVS value. ,Parse the JSON ,Loop through each row. ,Check whether an Employee ID already exists. ,Stop the submission if a duplicate is found.

 

try this 

function onSubmit() {

    var mrvs = g_form.getValue('employee_information');
    if (!mrvs)
        return true;

    var rows = JSON.parse(mrvs);
    var empIds = {};

    for (var i = 0; i < rows.length; i++) {

        var empId = (rows[i].employee_id || '').trim();

        if (!empId)
            continue;

        if (empIds[empId]) {
            g_form.addErrorMessage('Duplicate Employee ID "' + empId + '" is not allowed.');
            return false;
        }

        empIds[empId] = true;
    }

    return true;
}

 

here  employee_information  is your MRSV name which give you MRVS data you entered in json format .

 

 

 

thanks,

tejas😊

 

 

Tanushree Maiti
Tera Patron

Hi @vodnalar26 

 

 

  • Navigate to your Catalog Item and open the Multi-Row Variable Set.
  • Under the Variables related list, click on the Employee ID variable.
  • Check the Unique checkbox

Refer this post (screen shot is given) : Restrict duplicates in Multi-row Variable Set without script # Unique Attribute

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti