Restrict the duplicate entry on the multi row variable set

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 08:14 AM
Hi All,
Having a requirement that, we are having a form through that we are inserting records into hardware table.
On the form we are having a multirow variable set through that we are inserting the serial numbers based on that serial number records are inserted in the table.
while adding the serial numbers in the multi row variable set, we need to validate the entered serial number whether there is an asset record in the hardware table with the same serial number. if yes then need to restrict the form submition if no then able to submit the request.
Any suggestion on the above requirement to achieve.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 12:20 PM
Oh, so you're using Service Portal. Since this is onChange getXML will work the same, and does still work in SP.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('MRVSvalidation');
ga.addParam('sysparm_name', 'snExists');
ga.addParam('sysparm_sn', newValue);
gr.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'yes') {
g_form.clearValue('serial_number_1');
g_form.addErrorMessage('Serial Number already exists.');
} else {
g_form.clearMessages();
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 11:03 PM
Hi @Brad Bowman
Thanks for suggestion, but its still not restricting to abort the duplicate value entry.
Able to show error message as the record is already exists, but allowing the duplicate entry.
Any suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 10:03 AM
If serial_number_1 is the name of the variable, it sounds like there are no other mandatory variables in the MRVS and/or you are typing a serial number then clicking the Add button, so the add row action is completing before the script gets to the server and back. This is a challenge with the asynchronous nature of Service Portal. Here's one workaround that seemed to work in my mock-up of this use case.
Just add an alert before the GlideAjax call in the Client Script - something like 'Validating Serial Number...'. That seemed to allow the script to finish and abort the Add action in my testing. If that doesn't work in your environment for some reason I have a bit more convoluted workaround.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 11:00 AM
Hi @Brad Bowman
i think it's working, after alert its aborting the insert of the duplicate record.
Thank you @Brad Bowman .