onSubmit script error: ReferenceError: func is not defined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2019 08:08 AM
I have a huge issue on my hands (see details below):
When I select the "New Hire" radio button and select order now, the order now button does not work. When the other 2 choices are selected, the order now button works just fine. But when in the service portal view it works flawlessly no matter what radion button is selected. Does anyone have any leads as to why this is not working outside of the service portal?
There are 2 onSubmit scripts:
1. One to populate the visible variable list
2. And this one below:
function onSubmit() {
if (g_form.getValue('employee_type') == 'New Hire') {
//check to see if user is already in sys_user
var uua = new GlideAjax('u_UserUtilsAjax');
uua.addParam('sysparm_name', 'findUser');
uua.addParam('sysparm_identifier', g_form.getValue('vs_new_hire_user_id'));
uua.getXML(uuaCallback);
if ((answer != null) && (answer != '')) {
//"new user" exists in sys_user so set the requested for to the new hire
var cua = new GlideAjax('u_CartUtilsAjax');
cua.addParam('sysparm_name', 'setCartRequestedFor');
cua.addParam('sysparm_userId', g_user.userID);
cua.addParam('sysparm_reqForId', answer);
cua.getXML(cuaCallback);
} else {
//for "new users" not in sys_user, set requested for to the manager indicated by the user
var cua = new GlideAjax('u_CartUtilsAjax');
cua.addParam('sysparm_name', 'setCartRequestedFor');
cua.addParam('sysparm_userId', g_user.userID);
cua.addParam('sysparm_reqForId', g_form.getValue('vs_new_hire_hiring_manager'));
cua.getXML(cuaCallback);
}
} else {
//for "current employee" and "dept. transfer", set requested for to the normal default of the current user
//otherwise it may show a requested for from a previous "new user" incomplete order
var cua = new GlideAjax('u_CartUtilsAjax');
cua.addParam('sysparm_name', 'setCartRequestedFor');
cua.addParam('sysparm_userId', g_user.userID);
cua.addParam('sysparm_reqForId', g_user.userID);
cua.getXML(cuaCallback);
}
function uuaCallback(response){
var answer = response.responseXML.documentElement.getAttribute("uu");
}
function cuaCallback(response){
var answer = response.responseXML.documentElement.getAttribute("cu");
}
}
Any tips would be greatly appreciated!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 01:15 PM
If you disable these scripts does it allow the submission?
If you enable one does it still work?
If you enable the other and disable the opposite does it still work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 01:45 PM
I have not tried that, let me try disabling one of them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 02:01 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 03:02 PM
You are trying to access answer variable outside of a callBack function. answer can only be accessed inside the respective callBack function.
if ((answer != null) && (answer != '')) {
I also see that you are getting values from uu and cu attributes. Have you defined those elements in Server side?
Also, Is your requirement to stop user from submission if didn't meet certain criteria? Can you tell us what are you trying to achieve using this script