Not getting the answer from Script Include in onSubmit Catalog Client Script by using GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 06:09 AM
Hi,
Can anyone tell me that where am I going wrong. I am getting the null answer. Please refer the below scripts and screenshots.
Script Include:
var UserAuthorizationToFormSubmission = Class.create();
UserAuthorizationToFormSubmission.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkAuthorization : function(){
var userId = this.getParameter('sysparm_user_id');
return "userId";
},
type: 'UserAuthorizationToFormSubmission'
});
Client Script:
function onSubmit() {
var current_user = g_user.userID;
var auth_stat = new GlideAjax('UserAuthorizationToFormSubmission');
auth_stat.addParam('sysparm_user_id', current_user);
auth_stat.addParam('sysparm_name', 'checkAuthorization');
auth_stat.getXMLWait();
alert(auth_stat.getAnswer());
}
Output:
Please suggest why this is happening if I am trying to get the value from the script include which is client callable and called from the above mentioned client script by using the 'getXMLWait()' method.
Thanks,
Ankit

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 11:18 PM
What do you mean by
Now, I want this Catalog Item to be Submitted by :
-
The Manager of the user auto populated in the form.
-
Two static users defined in a system property.
You want the requested by field to be set as Manager of the user?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 11:32 PM
you can then use this logic and no script include Ajax required
1) create a string variable in your catalog item and auto populate those 2 static user sysIds as default value in it, then give order for this variable as highest and HIDE it using Catalog UI Policy
give those 2 users sysids in property separated by comma -> sysId1,sysId2
javascript: gs.getProperty('propertyName'); // give this in default value
2) use onSubmit and validate like this based on this hidden variable and manager variable
function onSubmit() {
var loggedInUser = g_user.userID;
var managerValue = g_form.getValue('managerVariableName'); // give the variable name here
var staticUsers = g_form.getValue('hiddenVariableName'); // give the variable name here
if (managerValue == loggedInUser || staticUsers.indexOf(loggedInUser) > -1) {
// allowed tosubmit
} else {
g_form.addErrorMessage('You should be manager or static user to submit');
return false;
}
}
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
05-12-2025 11:41 PM
Hi,
Write the same logic in the onChange of Name variable
1. Whenever the value changes for the Name variable, it will trigger the onChange of the Name variable client script.
2. Script Include is called in the onChange, it will check if the user is in the system property and in the same script include check for the user's manager and populate it in the Manager's variable.
3. If the user is not in the system property, then show a alert like "Not a valid User" and clear the name variable and as name variables is not mandatory, clear any mandatory variable as it will not allow the user to submit the form if a mandatory variable is not filled.
If the name variable is mandatory, clear only the name variable as that itself will not allow the user to submit the form.
4. If you are using any mandatory variable other than Name, you have to write the same logic in the onChange of that mandatory Variable.
Regards,
Deborah Brown
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 01:12 AM
Hi Everyone,
Thank you so much for your support and appreciated a lot. However, @Ankur Bawiskar's solution fitted for my requirement and worked fine for me when I implemented it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 01:34 AM
Glad to know.
Please mark my above response as correct and close the thread so that it helps future members.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader