Return false not working in on submit client script

Sajal Chatterje
Tera Contributor

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.

 

Client script
function onSubmit() {
    //Type appropriate comment here, and begin script below
    var ga = new GlideAjax('CheckDuplicateDelegate');
    ga.addParam('sysparm_name', 'chkDuplicate'); // the name has to be changed
    ga.addParam('sysparm_user', g_form.getValue('requested_by'));
    ga.addParam('sysparm_delegate', g_form.getValue('delegate_person'));

    ga.getXML(checkDuplicateDelegate);

    function checkDuplicateDelegate(response) {

        var answer = response.responseXML.documentElement.getAttribute("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 false;
}

 

 

 

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'
});
 

 

10 REPLIES 10

Hi @Sajal Chatterje , The issue is that date/time field is not compared as below

check_Delg.addQuery('starts', startdate);
  check_Delg.addQuery('ends', enddate);

 

You need to compare it as greater than OR less than 

if(startdate > enddate){
//perform some action
}

 

Could you provide me the requirement of comparing this field?

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.