Re: Form Instance Number

Home Forum General Form Instance Number Re: Form Instance Number

#5267

tmrhymer
Participant

If your forms go to a closed stage immediately after the first submission (which some of mine did) you will need to handle it with something like this. This was a solution given to me by one of the pf techs.

This will require one “hidden helper” text input field (txtFormSubmitted) to work correctly, with a default value of 0. In the form is opened event, at the beginning, you will add a simple branch that checks if txtFormSubmitted is equal to 1. If that is false, than just connect that to the normal behaviors you would want to run when the form is opened. If that is true than connect the branch to a run behavior command. This run behavior command should be set to run the behavior of your submit button.

Next you will need to modify the behavior of your submit button. For this, your submit button must be a regular button with a submit behavior so that you can add these extra behaviors. In your submit button is clicked event you will need a simple branch. That simple branch will check if txtFormSubmitted is equal to 0. If that is false, you will connect it to a set field command that sets txtFormSubmitted = 2. If that is true, you will connect the branch to a set field command that sets txtFormSubmitted = 1. After setting it to 1, you will want a set next stage command and set it to your first (default) stage. After that, add a Submit Data command with “Re-open Same Instance” checked.

So what you will end up with is the form first opens, and txtFormSubmitted will be set to 0, and your normal “form is opened” behaviors will execute. Then when the user submits the form the branch will see that txtFormSubmitted is set to 0 and will then set it to 1, set next stage to the default stage, and submit the form and re-open the instance. You will see the form open after it submits, but it happens very quickly. When the form re-opens, the branch you set up in the form is opened behavior will re-run the submit button is clicked event. This time the branch will see txtFormSubmitted is not equal to zero and will set it to 2. It has to set it to something other than 0 or 1, or the next time you open the form it will not work properly. After you set txtFormSubmitted to 2, you can add a set field to capture your form’s instance name.

This will allow you to capture it at the first stage. I hope that makes sense, it’s kind of hard to describe. It may sound kind of convoluted, but I’ve built that into all my forms and it works very well.