Code-based Actions: Verify user input
It is essential to verify the user input before you proceed. For example, we often encounter mismatches in the numerical order. A number verification or check can be created in the flow before proceeding further. To create a verification step you need data to verify and some verification rules.
Data to verify
We need some data that we can verify. You can use entities to extract parameters or you can use the complete user query. For more information, read Params.
Verification rules
To verify your data you need a couple of rules to be implemented. When the rules are in place, you can translate them to Java script code within Actions or Cloud Code. In this example, we have the following rules for the parameter:
- The parameter is between 7 and 12 characters
- The first 4 characters consist of "2019" or "2020"
- If correct, trigger the event "filenumber correct"
- If incorrect, trigger the event "filenumber incorrect"
Ensure to create an event with the corresponding names to avoid errors within the action code.
const filenumber = // use input query or param here
const years = [`2019`, `2020`]
if(filenumber.length > 7 && filenumber.length \< 12 &&
years.includes(filenumber.slice(0,4))){
trigger('filenumber correct');
}
else {
trigger('filenumber incorrect');
}
Updated 11 months ago