restrict through onsubmit if the record already exist in teh table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 02:11 AM
Having a requirement that,
Need to restrict the form submission if the values trying to enter in the table are already there.
we have a onchange script through which we are restrict the by only one field like as below.
clinet script :
function onSubmit() {
//Type appropriate comment here, and begin script below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('SoftwareModel');
ga.addParam('sysparm_name', 'modelExists');
ga.addParam('sysparm_sn', newValue);
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var Obj = JSON.parse(answer);
if (Obj.exists == 'yes') {
g_form.setValue('product_not_available',"existing");
spModal.open({
'message': "Software name already exist, would you like to update S/W version",
'title': "Update Software version",
'buttons': [{
label: 'yes',
primary: true
},
{
label: 'No',
cancel: true
}
],
'backdrop': 'static',
'keyboard': false
}).then(function(confirm) {
g_form.setValue('product_not_available',' ');
g_form.setVisible('vendor', true);
g_form.setValue('vendor', Obj.product);
g_form.setReadOnly('vendor', true);
g_form.setVisible('software_version', true);
g_form.setMandatory('software_version', true);
}, function() {
});
} else {
g_form.setVisible('vendor', true);
g_form.setMandatory('vendor', true);
g_form.setVisible('software_version', true);
//g_form.setMandatory('software_version', true);
}
}
}
}
script include:
var SoftwareModel = Class.create();
SoftwareModel.prototype = Object.extendsObject(AbstractAjaxProcessor, {
modelExists: function() {
var answer = {};
var assetGR = new GlideRecord('cmdb_software_product_model');
assetGR.addQuery('product',this.getParameter('sysparm_sn'));
assetGR.query();
if (assetGR.next()) {
//answer = 'yes';
answer.product = assetGR.getValue('manufacturer');
answer.exists = "yes";
} else {
answer.exists = "no";
}
var output = JSON.stringify(answer);
return output;
},
type: 'SoftwareModel'
});
can i have suggestion to make the changes to work on the on submit.
The values which i need to query are
Any suggestions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 02:26 AM
Hi @Community Alums
please follow the thread it will be helpful to you:-
if-record-exist-in-the-table-should-not-allow
Please mark reply as Helpful/Correct, if applicable. Thanks!