Submission APIs

To increase the options available to Form Developers there are three separate submission API’s (PreSubmit, PreApproval, and PreRejection). They are used to trigger JS code right before a form gets pushed through to submission. This allows form developers to create custom code that is triggered right before submission. This code can be custom validation, form changes made only for printing/receipt, increment fields, or anything else a developer could think to use it for.

PreSubmit

The PreSubmit API is a catch all, meaning that it will trigger before any kind of submission (submit, approval, rejection, any).

  1. Takes no parameters and returns a new object

//canSubmit is a boolean value that represents if the validation has succeeded //errorMessage is displayed in the toast if canSubmit is false function PreSubmit(){ var result = { canSubmit: false, errorMessage: "Validation Failed" } if(customValidation == true){ result.canSubmit = true } return result }

 

Remember if routing for approval and using PreSubmit API, PreSubmit is a catch all that will be triggered on submit, approval, or rejection.

PreApproval / PreReject

The PreApprove and PreReject API’s work in exactly the same way as the PreSubmit API. However PreApprove will only trigger when a user approves a routed form, and PreReject will only trigger when a user rejects a form.

        function PreReject() {             let canReject = true //on rejection sets value of formRouted to Null             $('#formRouted').val('')             $('#formRouted').trigger('change')             Forms_inMotion("elementdataupdate")             var object = {                 canReject: canReject,                 errorMessage: "Required fields are missing, please fill out fields highlighted in red."             }             return object;         }         function PreApprove() {             let canApprove = true //On approve routingCheck and validateDept are called to determine if the //form can be submitted             canApprove = routingCheck()             canApprove = validateDept()             Forms_inMotion("elementdataupdate")             var object = {                 canApprove: canApprove,                 errorMessage: "Required fields are missing, please fill out fields highlighted in red."             }             return object;         }