- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 10:49 PM
HiAll
I am writing a onsubit client script where i want to check if the fields are populated with correct values or not before submitting the form.
Reason - we have onchange client script but we saw that sometimes the value gets corrupted or beomes undfined on submit and it creates an issue..
function onSubmit() {
var user = g_form.getValue('user'); //variable name. I am fetching the values on user table to populate 2 fields on catalog item.
var scriptInclude = new GlideAjax("UserData");
scriptInclude.addParam('sysparm_name','data');
scriptInclude.addParam('sysparm_id',user);
scriptInclude.getXMLWait(retrieveValues);
//Type appropriate comment here, and begin script below
}
function retrieveValues(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
var Value = answer.split(',');
var m,n,s;
m =g_form.getValue('userd');
n =g_form.getValue('manager');
s =g_form.getValue('department');
alert(m +Value[0].toString());
alert(Value[1].toString());
alert(Value[2].toString());
if(m == Value[0].toString() && n ==Value[1].toString() && s==Value[2].toString())
{
return true;
}
else{
alert("Please re-enter the User again");
return false;
}
}
This submits and i dnt see any alert. how can i match what was entered on form and the user value fetched.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 11:00 PM
Hi Surya,
That looks like asynchronous call instead of a synchronous one, which is what you need at a onSubmit script.
getXMLWait shouldn't be taking a callback method as a parameter
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 11:27 PM
You're welcome Surya. I'm glad it was helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 11:05 PM
Also, take a look to the very popular way to do a hybrid client + server side code in one ui action. That's great for doing validations when needed on the client side
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 11:06 PM
I hope this helps!