Catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
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
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
56m ago
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😊