Stages
A stage is a step in your Workflow. It is a Python file that will be executed when your Workflow reaches that point in its run.
Depending on the trigger you need for that stage, you can create it as a Form, Hook, Job or Script.
Forms: manually triggered stages with a friendly UI. Add them into a Workflow whenever user input is needed in a process.
Jobs: stages scheduled to be executed periodically.
Hooks: stages triggered by authorized HTTP requests sent to their endpoint.
Ok task: a plain Python script, whose trigger is a task sent by previous stages in the Workflow.
Let's check the Apply to Dunder Mifflin stage. Click on the Stages tab in the sidebar.
And select the Apply to Dunder Mifflin stage.
Form Editor
The Apply to Dunder Mifflin stage is a Form. The Editor shows the Form's code to the left and a preview of the UI to the right.
By executing the form in the preview, you can see how the python code is shown to the user. The code is executed procedurely until it reaches an Abstra widget.
Forms executed in preview will not create new threads unless you toggle the Workflow OFF switch at the top of the preview.
With this knowledge, you can easily update the code to your needs. For example, you can add a display
widget before the best_movie input to show a welcome message to the user. By saving and executing the form you will see the new display after the start message.
af.display("Welcome to Dunder Mifflin!")
You can check the complete list of widgets here.
The input widgets will get an input from the user, and you can assign it to a variable as we did with the best_movie
variable.
best_movie = af.read_multiple_choice("What is the best movie ever made?", options=[
"Die Hard",
"Devil Wears Prada",
"Weekend at Bernie's",
"American Psycho",
"Legally Blond",
"Wall-E",
"Threat Level: Midnight"
])
The code of this form is just getting inputs from the user. In the other script, Application Review, that you can access by getting back to the Stages page by clicking on the left arrow in the top left corner and selecting the Application Review stage, we process this data, processing it and sending an email to the user with the application status.
To share variables between stages, you can send tasks from the upcoming stages via the send_task
function from the abstra.tasks
module. To retrieve the task in a on task stage, you can use the get_trigger_task
function from the same module to access the task that triggered the current script run. More info about this in the SDK Reference/Workflows/Send task.
In the Application Review stage, we are retrieving the user inputs, adding to the variable reasons
why the user wasn't hired if the answers were not certain values, and sending the approval/rejection email. Once this stage is a script, instead of a form, it doesn't require user interaction and it doesn't have a preview.
Once it depends on a task to be executed, you can create a task manually by clicking the Tasks tab, then "Add new" and filling the necessary data.
And that's the basics about stages! You can get more info about the different types of stages in the docs of each type: Forms, Jobs and Hooks.