In this tutorial you will learn about using advanced workflow options: action visibility, execution condition, confirmation, error message and actionstep set cell value.
To show how these work we will create a simple app for group voting.
Start with creating a new app adding a spreadsheet widget with one cell. In this cell write a matter to vote on e.g.: 'Do you want to change working hours to 9 a.m to 5 p.m' ?
Add a second spreadsheet and in its first cell write 0 value. Set cell type to 'number' and make the cell editable.
Add one more spreadsheet section and in first cells of columns A and B write 'votes for' and 'votes against'. Under both of these put 0 value, set cells type to 'number' and set the cells as editable.
Add workflow actions widget.
Add a new workflow state 'decision' and a 'send' action from the start to it. Add two more actions:'Yes' and 'No' starting and ending at the decision 'state'. In 'decision' state in 'editor' field choose 'multiple'. This change is needed because otherwise first person to enter the app would take ability to edit away from all of the other users.
On enter to 'decision' state add 'set editors' or 'add editors' actionstep. Now in editors field you can type All - then all of your sites users will be able to vote; or choose some of the users and write their emails in cells of section 2 spreadsheet.
Set this section as not visible by writing =false in visibility field.
With our current workflow settings actions 'yes' and 'no' can be done an infinite amount of times. We want for the summed number of 'yes' and 'no' actions to be equal to the number of voters. In our case we have only two voters and that is why we want for the decision to be made two times. Add another set of 'yes' and 'no' actions and a 'finished' state.
We want for the app to go into 'finished' state after the last voter makes a decision.
At the moment we have two sets of 'yes' and 'no' actions visible. Before we change that there is one more thing we have to do. It is the 'set cell value' actionstep on enter to 'decision' state. Fill in its options same way as below:
Now, every time a user opens the app the value set at the start to 0 will increase by 1. Thanks to this we can now create conditions for 'yes' and 'no' actions visibility.
In first set of 'yes' and 'no' in 'action visibility' field put this formula:
In case you have two voters. In other case replace 2 in formula with your number of voters.
In second set put an identical formula and only change the '<' sign to '=':
If we want to know how users voted after the voting has finished we will need to increase values in section 3.
To make it possible we need to add 'set cell value' actionstep in every 'yes' and 'no' action. Fill their fields as shown:
for 'yes' actions:
for 'no' actions:
4.One person- one vote
If we want for the user to vote only once we need to make some more changes in workflow.
First, add new rows to section 2 spreadsheet - it should have 6 of them altogether. 4th cell set as editable and leave it empty.
Go back to workflow tab and to every 'yes' or 'no' action add 'set cell value' actionstep. The cell we will be setting a value for is the empty editable one in section 2. Its value will be a formula which will put a currently voting user email address in the empty cell. In this cell email addresses will appear after every vote.
Formula : =CONCAT(section2.a4,CURRENTUSEREMAIL(),';')
We can use this fact to exclude users who already voted from further voting. We will use the fact that their email addresses are already in the cell.
Put this formula in 5th cell of section 2 spreadsheet:
Set type of this cell as 'Checkbox'.
This formula checks if current users email address is already in the cell or not.
Now we need to prevent users who already voted from making any actions. To do so let's put this formula in 'execution condition' field for every 'yes' and 'no' action.
We can do it by copying the formula and pasting it in every field or by simply writing this cell address :
Now let's write an error message- it is a message that appears when the execution condition is not met. In our case it is voting for a second time. Let's put this type of message in the last cell of section 2. It can be for example: 'You cannot vote twice.'
Next write this cell's address in every 'error message' field for 'yes' and 'no' actions.
The last thing that we can add is a confirmation for 'no' actions. Confirmation in our app is a window that will appear when a user votes 'no'. Choose the confirmation option and in confirmation title write for example: Explain why. We want the person voting against to explain why he or she disagrees.
Lastly, add yourself as the app creator, save the app and run it to test how it works.
After trying to vote for a second time: