How can we run code to set a field value when submitting and moving to the next step?

There is no "onClick" event on the submit button....

We need to update a status field when the step changes

If we check the stage on "beforeSave" event of the form then the new stage is not known in "BO.getCurrentStage()". If we check in "afterSave" then the value is correct - but any changes to the value are (obviously) not saved 😉

/John

You can use the validateButtonPressed event on the form. Below is example of how we have done it for an app.

//Request is being accepted, set status to In Process
if(pActionId === 'S_Accept'){
if(confirm('Are you sure you want to Accept the request and place In Process?')) {
BO.F_DocStatus.setValue("In Process"); //Update Status
BO.F_DateAccepted.setValue(new Date()); //Update Date
BO.F_Technician.setValue(app.getCurrentUserDisplayName()); //update technician field
return true; //Save Update
} //End of Acceptance Confirmation

return false; //Do not save
}//End of Acceptance

Already played a little with this event.

The thing is that we already have validation on the form (some fields need to be filled in). So how do we handle the "built-in" validation - and then just process the change of the status if everything else validates correctly?

I'll play a little further around with it and see if I can make it work...

By naming the action buttons after the state it changes to I can set it correctly.

Thanks!

You have a couple of options here (there is not a "getNextStage()" action, yet)

  • You could use a custom button instead of the submit button and check the current stage and based on that perform the action (example here: https://hclwiki.atlassian.net/wiki/spaces/HDV/pages/38502517/Using+a+Button+instead+of+an+Action+Button+to+Submit+a+Form)
  • You could do the beforeSave() and based on the current stage (and you know the next stage) perform the action based on that (similar to above in that you need to know what the next stage is based on current)
  • Or when the app opens the next time, set the field value based on the current stage - but this may be too late to report
  • You could do the afterSave() and call a "hidden" submit that saves the form again but stays in the same stage...

Hi Ken, I've got a question to point 4 of your list: how would realize a button to simply save without moving stages?