Unable to submit record on catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2023 10:47 PM - edited 08-12-2023 11:00 PM
If (answer == true )record should be submit , But unable to submit the record
Catalog client script on submit :-
var isAlertDisplayed = false; // Flag to prevent multiple alerts
function onSubmit() {
var getvalue = g_form.getValue('spreadsheet_name');
if (g_form.getValue('fnd_actions') = 'fnd_action_create') {
var name = new GlideAjax('BIvalidationresultingNameAJAX');
name.addParam('sysparm_name', 'validationname');
name.addParam('sysparm_ci_name', g_form.getValue('spreadsheet_name'));
name.getXML(Callback);
// Return false here to prevent immediate form submission
return false;
} else {
// If fndActions is 'fnd_action_modify', allow form submission
return true;
}
}
function Callback(response) {
if (isAlertDisplayed) {
return false; // Avoid executing multiple times
}
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if (answer === 'false') {
isAlertDisplayed = true; // Set the flag
alert("Resulting Name Interface already exists. Please provide a new Resulting Name Interface.");
g_form.addErrorMessage("Resulting Name Interface already exists. Please provide a new Resulting Name Interface.");
return false; // Prevent form submission
} else {
return true; // Allow form submission
}
}
Script include :-
@Ankur Bawiskar
Can anyone help me

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2023 12:38 AM
Hi @Anish9515,
Could you please try rewriting your code in a different way?
Something along the lines of
function onSubmit() {
var ci_name = g_form.getValue('spreadsheet_name');
if (g_form.getValue('fnd_actions') = 'fnd_action_create') {
if (validation_function(ci_name)) {
return true;
}
else {
g_form.addErrorMessage("Resulting Name Interface already exists. Please provide a new Resulting Name Interface.");
return false;
}
}
}
function validation_function(ci_name) {
// Perform validation using GlideAjax
// return true or false based on the business logic
}
Let me know if this helps.
Also, you may want to check out this link. - Asynchronous onSubmit Catalog/Client Scripts in ServiceNow - ServiceNow Developer Pro-Tips (snprotip...