Create Unique records from multi row variable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Hi
We have a Multi-Row Variable Set (MRVS) named "MRP PRODUCTS PLANNING". Inside this variable set, there is a select box variable called "Plant & Storage Location" .
Users should be allowed to create only one record for each value in the dropdown. If there are only ten available drop down values, a maximum of ten records should be created in the MRVS. Duplicate selections should not be allowed, and users should not be able to create multiple records with the same Plant & Storage Location value.
How can we implement this functionality?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
how and from where you are creating the records from MRVS?
Flow or workflow or business rule?
there you can add logic
show your MRVS variables form
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
approach to take
1) limit MRVS to 3 rows, see this link
2) On the select box variable Plant & Storage Location inside the MRVS:
Set Unique = true.
Keep it Mandatory = true
3) use catalog client script onSubmit to validate the MRVS JSON
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
36m ago
Hi @Amrutha K V
Try this Validation using onSubmit Catalog client script.
- Navigate to Catalog Client Scripts and click New.
- Name: Give your script a descriptive name (e.g., Prevent Duplicate MRVS Rows).
- UI Type: Select All or Desktop/Service Portal.
- Type: Set to onSubmit.
- Applies to: Select A Catalog Item.
- Catalog Item: Select your specific catalog item
function onSubmit() {
g_form.clearMessages();
var mrvsStr = g_form.getValue('mrvs_products_planning'); // Replace with your MRVS internal name
if (!mrvsStr || mrvsStr == '[]') {
return true;
}
var mrvsData = JSON.parse(mrvsStr);
if (mrvsData.length > 10) {
g_form.addErrorMessage("You cannot create more than 10 records in the MRP PRODUCTS PLANNING table.");
return false;
}
var selectedStoragePlants = [];
var isDuplicate = false;
for (var i = 0; i < mrvsData.length; i++) {
var plantValue = mrvsData[i].plant_and_storage_location; // Replace with your variable's internal name
if (selectedStoragePlants.indexOf(plantValue) > -1) {
isDuplicate = true;
break;
} else {
selectedStoragePlants.push(plantValue);
}
}
if (isDuplicate) {
g_form.addErrorMessage("Duplicate Plant & Storage Location values are not allowed. Each plant must be selected only once.");
return false;
}
return true;
}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti