Current.setAbortAction() and gs.message not working in Script Include called by Catalog Client Script

anubhavr
Giga Expert

I have a Joiner Form Catalog Item where new Joinees enter their   Start Date and End Date for their Joining. Here 'Start Date' and 'End Date' are variables of 'Joiner form' Item. I was trying to write a Catalog Client Script for type = onSubmit. I tried by passing Start Date and End date values to Script include and compare it. All are working fine but current.setAbortAction() and gs.getMessage() funcions are not working. So even after showing error message by g_form.addErrorMessage() in Client script the record gets created. I want to abort this record submission.

1 ACCEPTED SOLUTION

Here's the client script I used to validate start/end dates on a record producer.



function onSubmit() {


    var jsStartDate = new Date(g_form.getValue('work_start'));


    var jsEndDate     = new Date(g_form.getValue('work_end'));


    var jsToday         = new Date();


   


    if (jsStartDate < jsToday) {


          alert(getMessage('loaner_error_start_before_today'));


    return false;


    }


   


    if (jsEndDate < jsStartDate) {


          alert(getMessage('loaner_error_end_before_start'));


    return false;


    }


    return true;    


}



Then I also run a (before insert/update) business rule when fulfillers are updating the record in case two pick the same resource, one submits and it's OK and the second gets a conflict.



(function executeRule(current, previous /*null when async*/) {



var start = new GlideDateTime(current.work_start).getNumericValue();


var end = new GlideDateTime(current.work_end).getNumericValue();



if (start > end) {


  var msg = gs.getMessage('loaner_error_end_before_start');


  gs.addErrorMessage(msg);


  current.work_start.setError(msg);


  current.setAbortAction(true);


}



})(current, previous);


View solution in original post

6 REPLIES 6

Chuck Tomasi
Tera Patron

To get an onSubmit() script to stop, simply return false. current is not an available object in client scripts (catalog or otherwise.)


Hi Chuck, I am calling a Script Include from Catalog Client Script. In that Script Include I have called current.setAbortAction() and gs.getMessage() function. Please see the screenshots of my Script include and Catalog Client Script.



This is my Script include:



find_real_file.png


This is my Catalog Client Script:



find_real_file.png


Here's the client script I used to validate start/end dates on a record producer.



function onSubmit() {


    var jsStartDate = new Date(g_form.getValue('work_start'));


    var jsEndDate     = new Date(g_form.getValue('work_end'));


    var jsToday         = new Date();


   


    if (jsStartDate < jsToday) {


          alert(getMessage('loaner_error_start_before_today'));


    return false;


    }


   


    if (jsEndDate < jsStartDate) {


          alert(getMessage('loaner_error_end_before_start'));


    return false;


    }


    return true;    


}



Then I also run a (before insert/update) business rule when fulfillers are updating the record in case two pick the same resource, one submits and it's OK and the second gets a conflict.



(function executeRule(current, previous /*null when async*/) {



var start = new GlideDateTime(current.work_start).getNumericValue();


var end = new GlideDateTime(current.work_end).getNumericValue();



if (start > end) {


  var msg = gs.getMessage('loaner_error_end_before_start');


  gs.addErrorMessage(msg);


  current.work_start.setError(msg);


  current.setAbortAction(true);


}



})(current, previous);


Hi Chuck,



Client script for onSubmit is working fine for portal also.



Thanks.