Record Producer still being submitted although return set to false
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2017 01:55 PM
Hey guys,
I have an onSubmit Catalog Client Script, that prevents submission of a form depending on what's returned by a GlideAjax function.
Here is my script:
function onSubmit() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('TestLocationScript');
ga.addParam('sysparm_name','testLocationScript');
ga.addParam('sysparm_subject_person',g_form.getValue('u_subject_person'));
ga.addParam('sysparm_effective_date',g_form.getDisplayValue('u_effective_date'));
ga.addParam('sysparm_opened_for',g_form.getDisplayValue('u_opened_for'));
var newVal = ga.getXML(doSomething);
var dup = g_form.getValue('duplicate');
if (dup == 'true'){
g_form.clearMessages();
g_form.addInfoMessage("Request can not be submited for this employee");
return false;
} else {
return true;
}
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
g_form.setValue('duplicate', 'true');
} else {
g_form.setValue('duplicate', 'false');
}
}
}
Even though, the response is coming as true which should return false for the onSubmit function, the form still goes ahead with the submission. Could someone tell what I am doing wrong here and successfully prevent submission for such a case?
Thanks,
Raed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2017 02:02 PM
since it's getXML, the code on like 13-19 is executing before the response from server is coming back. so it when it sets the values, that check is already done.
Do like this:
Was a bit tired.. gimme a min to fix the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2017 02:12 PM
Thanks for the reply Goran. I tried your changes. It shows the Can't be submitted message, however it still submits the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2017 02:16 PM
yea... was to tired.. onSubmit, should use getXMLWait() instead. Se the post below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2017 02:16 PM
function onSubmit() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('TestLocationScript');
ga.addParam('sysparm_name','testLocationScript');
ga.addParam('sysparm_subject_person',g_form.getValue('u_subject_person'));
ga.addParam('sysparm_effective_date',g_form.getDisplayValue('u_effective_date'));
ga.addParam('sysparm_opened_for',g_form.getDisplayValue('u_opened_for'));
ga.getXMLWait();
var newVal = ga.getAnswer();
if (newVal == 'true'){
g_form.clearMessages();
g_form.addInfoMessage("Request can not be submited for this employee");
g_form.setValue('duplicate', 'true');
return false;
} else {
g_form.setValue('duplicate', 'false');
return true;
}
}