Return false not working in on submit client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2024 09:15 PM
Hello Community,
There is a requirement where if a catalog form passes all the validations then only the form should be submitted otherwise we have to abort the on submit. It should not submit anything.
I used return false in my client script but still user able to submit the form. Please let me know for any other alternative to abort on submit action. Below is my script i used.
Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 06:08 AM
Hello @SN_Learn ,
Everything working fine and it also showing the message. But the issue is although its showing error message , it is redirecting to different page. We don't want to redirect to different page if it is not passing the validations.How can I handle this???
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 08:39 AM
Hi @Sajal Chatterje ,
I tried in PDI just now with the below code:
Script Include:
var CheckDuplicateDelegate = Class.create();
CheckDuplicateDelegate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
chkDuplicate: function() {
var requestedby = this.getParameter('sysparm_user');
var delegateperson = this.getParameter('sysparm_delegate');
var check_Delg = new GlideRecord('sys_user_delegate');
check_Delg.addQuery('user', requestedby);
check_Delg.addQuery('delegate', delegateperson);
check_Delg.query();
if (check_Delg.hasNext())
return true;
else
return false;
},
type: 'CheckDuplicateDelegate'
});
onSubmit Client Script:
function onSubmit() {
if (g_scratchpad._ajaxChecked) {
g_scratchpad._ajaxChecked = null;
return true;
}
g_scratchpad._action = g_form.getActionName();
g_scratchpad._ajaxChecked = false;
var ga = new GlideAjax('CheckDuplicateDelegate');
ga.addParam('sysparm_name', 'chkDuplicate');
ga.addParam('sysparm_user', g_form.getValue('requested_by'));
ga.addParam('sysparm_delegate', g_form.getValue('delegate_person'));
ga.getXMLAnswer(function(answer) {
if (answer == "true") {
g_form.addErrorMessage("There is already an existing delegation for this user and delegate with the same delegated items within the same time period.");
return;
}
g_scratchpad._ajaxChecked = true;
if (typeof g_form.orderNow != 'undefined') {
g_form.orderNow();
} else {
g_form.submit(g_scratchpad._action);
}
});
return false;
}
Output:
Let me know if the issue still persist, also please share the screenshot where it is redirecting to?
If it is a record producer check the script part if there is anything defined over there such as portal.redirect
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 08:23 AM
Hello @SN_Learn ,
Yes, it is working with two parameters but when I increased the parameters to 4.Its not working Like the below I added 4 parameters.Could you please check with 4 parameters??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 08:27 AM - edited 07-25-2024 08:28 AM
Thanks for providing the details.
Could you please share the Client script and Script Include to debug it? Also start date and end date is date type field or date/time field and what is the requirement?
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 08:31 AM
Hello @SN_Learn ,
Client script
function onSubmit() {