Catalog OnSubmit Script is not working in ESC portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 11:12 PM
Hello Team,
I have written the following code for my requirement. I need to check whether the user's manager is active or not. If the manager is inactive, a confirmation popup should appear before submitting the request. If the user clicks "OK," the form should submit; otherwise, if they click "Cancel," the form should not be submitted.
I have written the client script and script include code below.
Could you please guide me on this?
Thank you!
Client Script:
function onSubmit() {
var gr = new GlideAjax('check_hrs');
gr.addParam('sysparm_name', 'manager_active');
gr.addParam('sysparm_manager', g_form.getValue('subject_person_s_manager'));
gr.getXMLAnswer(setAnswer);
return false; // Prevent form submission until the response is received
}
function setAnswer(answer) {
if (answer == 'false') {
var anna = confirm('Please Confirm: User does not have a manager.');
if (!anna) {
return false; // Stop execution if the user cancels
}
}
if (g_scratchpad.isFormValid) {
return true;
}
g_scratchpad.isFormValid = true;
g_form.submit(g_form.getActionName());
}
Script Include
var check_hrs = Class.create();
check_hrs.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
demo: function() {
var sdate = this.getParameter('sysparm_form');
var gh = new GlideDateTime(sdate);
var gd = new GlideDateTime();
var gdd = gd.getDisplayValue();
var gddd = new GlideDateTime(gdd);
var gt = GlideDateTime.subtract(gddd, gh);
var sec = gt.getNumericValue();
if (sec > 14400000) {
return true;
} else {
return false;
}
},
check_manager: function() {
var gr = new GlideRecord('sys_user');
gr.get(this.getParameter('sys_user_id'));
if (gr.manager) {
return true;
} else {
return false;
}
},
manager_active: function() {
var gr = new GlideRecord('sys_user');
if(gr.get(this.getParameter('sysparm_manager'))){
if(gr.active.toString() == 'true'){
return true;
}else{
return false;
}
} else{
return 'No Manager';
}
},
type: 'check_hrs'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 11:39 PM
Hi @Mark Wood
one observation - the script include manager_active is almost correct, but you are returning true or false (booleans) directly from the server-side code, while the client script expects these responses to be processed as strings ('true' or 'false'), not booleans.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 12:00 AM
Hi @Mark Wood ,
In client side use alerts or info message to check what exactly your getting into answer ,
Try returning from SI as string below,Insted Boolean 0 or 1.
if (gr.active) {
return 'true';
} else {
return 'false';
}
If my response helped, please mark it as the accepted solution ✅ and give a thumbs up👍.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 12:34 AM
try this
manager_active: function() {
var gr = new GlideRecord('sys_user');
if(gr.get(this.getParameter('sysparm_manager'))){
if(gr.active.toString() == 'true'){
return 'true';
}else{
return 'false';
}
} else{
return 'No Manager';
}
},
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 11:22 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader