onSubmit Catalog Client Script not working for Non-Admin Users
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2025 09:18 AM
I have this working onSubmit Catalog Client Script code. When I try it in ESC portal or Native UI as a system administrator or a user with Admin role, it works fine. But when I try by impersonating as a non-admin user and try to submit a catalog request. It shows it had some error.
Below I have shared the Script:
var isSubmitting = false; // Global flag to track submission status
function onSubmit() {
if (!g_form.ajaxComplete && !isSubmitting) {
getData();
return false;
}
return true; // Allow submission if `g_form.ajaxComplete` is true
}
function getData() {
var groupName = g_form.getValue('group_name');
var memberCount = g_form.getValue('EU06') ? g_form.getValue('EU06').split(',').length : 0;
var ga = new GlideAjax('isGroupCreated');
ga.addParam('sysparm_name', 'isNameExists');
ga.addParam('Group_Name', groupName);
// Make an asynchronous call
ga.getXMLAnswer(function(response) {
if (response == 'false' || response === false) {
// If group name exists, show error and prevent submission
alert('Group with the same name already exists. Please try with a different name.');
g_form.addErrorMessage('Submission canceled due to duplicate group name.');
} else if (response == 'true' || response === true) {
// If name is unique, prompt user for confirmation
var confirmation = confirm(
'Please confirm your request details:\n' +
'Group Name: ' + groupName + '\n' +
'Description: ' + g_form.getValue('EU02') + '\n' +
'Group Email: ' + g_form.getValue('EU03') + '\n' +
'Manager for the group: ' + g_form.getDisplayValue('EU04') + '\n' +
'Number of Members: ' + memberCount
);
if (confirmation) {
// Set flag to true to indicate submission in progress
isSubmitting = true;
g_form.ajaxComplete = true;
// Submit the form based on the environment
if (window == null || window === 'NULL') {
g_form.submit();
} else {
$j("#oi_order_now_button").trigger('click');
$j("#submit_button").trigger('click');
}
} else {
g_form.addErrorMessage('Submission canceled by the user.');
}
} else {
// Handle unexpected errors
g_form.addErrorMessage('Unexpected error occurred during form submission.');
}
});
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2025 10:28 AM
Check your Script Include to see if there is anything listed in the Access Controls related list.