Documentation

Workflow Script Tutorial

Workflow scripts can be used to alter tasks in subscriptions or triggered workflows. The foremost use of this is for generating emails and altering credentials.

Let's create a new trigger based on reservations being modified to show how we can use scripts to customize an email. We'll start by going to Workflows -> Triggers in the administrative panel, then selecting "Create New Trigger".

create_trigger_example.png

Here a testing trigger has been set up so that it triggers on reservation modifications for any reservation for the resource Testy.

example_trigger.png

Now we can add some tasks below. The first task I will add is a script and the second task will be an email.

scripts_and_email_task_for_example_trigger.png

In order for the email to use the output of the script, we need to assign a task ID to the script task and then put that task ID into the "Input Script Task ID" text box. This will indicate to the email task that it should use the output of the script task when generating an email. The script task here is assigned the id script_task_id.

example_trigger_tasks_script_id_assigned.png

There is some extremely helpful information about the expected input of the email task in script terms hidden in the help text for "Input Script Task ID":

input_script_task_help_box_for_email.png

We can use the information here to craft an email by writing a script. Below is an example script that we can use to test the feature.

1return {
2 'subject': "This is a subject line",
3 'body': "Hello " + reservation["reserved_for"]["display_name"] +
4 ', thank you for modifying your reservation',
5}
example_trigger_tasks_script_hello_user.png

Now we're ready to test our trigger. To do this effectively we need to make a reservation, then modify the reservation, then get the reservation ID for the modified reservation. Go to the calendar page for the resource and do so, and then click on the reservation again after modifying it and click on the reservation ID in the bottom left of the reservation viewing modal to copy it to the clipboard.

copy_reservation_id_example.png

Now, navigate back to the the trigger you are working on (it should be in the Paused tab). From here, go to the "Testing" box and paste the reservation ID.

testing_reservation_id_in_trigger_task.png

Now try the "Test Event Hook Run" button. You should be greeted with a successful test run along with the output of each task. You can click on each individual output to expand them. As you can see, the body of the email includes the display name of the user the reservation was for.

successfully_trigger_run_test.png

Finally, to activate your new trigger workflow, navigate to the top of the page and select "Activate or Resume Trigger".

activate_or_resume_trigger.png

This will enable your trigger, making it so that this email is sent to every user who modifies their reservation for the resource Testy.