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-21-2023 10:46 AM
I would use an onChange Catalog Client Script that applies to the MRVS, not the Catalog Item, when the serial number variable changes, and make this a mandatory variable. The script will do an easy Glide Ajax call to a client callable Script Include, passing in the newValue. The SI will query the asset table for this value and return yes or no. If yes, clear the variable which will prevent adding the row.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 11:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 11:51 AM
Here's an onChange Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CatUtils');
ga.addParam('sysparm_name', 'snExists');
ga.addParam('sysparm_sn', newValue);
ga.getXMLWait();
var answer = ga.getAnswer();
if (answer == 'yes') {
g_form.clearValue('v_serial_number');
g_form.addErrorMessage('Serial Number already exists.');
} else {
g_form.clearMessages();
}
}
And A Script Include:
var CatUtils = Class.create();
CatUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
snExists: function() {
var answer = 'no';
var assetGR = new GlideRecord('alm_hardware');
assetGR.addQuery('serial_number', this.getParameter('sysparm_sn'));
assetGR.query();
if (assetGR.next()) {
answer = 'yes';
}
return answer;
},
type: 'CatUtils'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 11:18 AM
Hi @Brad Bowman
Tried as suggested,
but its not working getting console error as getXMLWait is not supported kind of.
and its allowing the value to enter also.
the serial number Abc123 record is already there on the hardware table, it still allows the value to enter.
Any suggestions.