Add a JSON workflow trigger using the code editor
Adding a workflow trigger
You can automate some actions in a custom workflow by adding one or more workflow triggers. A workflow trigger listens for a specific workflow event to occur, such as a change of state, and if any set conditions are met, it actions a change. A workflow trigger can be added as JSON code using the code editor.
Adding a trigger requires a number of JSON properties, values and data:
The code editor provides the JSON schema autocomplete and dropdown dialog box for each of these.
Adding a trigger
In the code editor, you add a trigger after the closing bracket for the last "state"
.
add a comma after the last square bracket ] but before the overall workflow closing curly brace }
add
""
to display the JSON schema options
use the keyboard arrow keys to highlight and select triggers array
Adding a trigger to send a custom email notification
You must now add the workflow trigger parameters and values.
In some workflows, the trigger property is already added: the event, conditions, and actions must be added for each required trigger.
For example, when using Create New Workflow in the space document management dashboard:
the starter workflow has no workflow trigger
the empty
"triggers":[ ]
property is available at the end of the template code to add one or more triggers
The trigger properties are added as contents to the square brackets [ ] in "triggers": [ ]
.
When adding curly brackets { }
, square brackets [ ]
, and apostrophes ""
, the editor adds these in pairs. You only need to type the first character.
Trigger event - change of state
add the event object
within the square brackets [ ]
type
{"
this adds the curly bracket and apostrophe pair
{""}
select and add event string from the JSON schema dropdown
To activate the JSON schema prompt, click within the ""
. If the JSON schema dropdown disappears before you select a property, retype the apostrophes to display the dropdown again.
add a single event name for the trigger to listen for
after
"event":
add the apostrophes""
choose an event name from the JSON schema dropdown
In our example, we have chosen on-change-state
.
All available event names are displayed in the JSON schema. Scroll with the mouse in the JSON Schema box to view additional options. Click the keyboard’s Arrow keys to move up or down to highlight an event and select it.
Trigger condition - state
You must add a comma for some properties to add the next JSON code item and activate the JSON schema dropdown.
add a condition for the chosen event
after “on-change-state”
add a comma
add apostrophes
""
choose conditions array in the schema
add any conditions for the event
within the square brackets in
"conditions": [ ]
type
{"
to add the curly bracket and apostrophe pair{""}
choose state string in the schema to constrain the trigger to listen for a change to a selected workflow state
The code editor displays a prompt to add an existing state in the workflow for the state condition.
add the name of an existing state in the workflow with the provided apostrophes in the JSON
""
In our example, we constrained our trigger to listen for a change of state to the Rejected state.
Trigger action - send an email
Add an action to perform when the event occurs, and the conditions are met.
add a comma after the closing conditions square bracket ]
click within the apostrophes
""
( or type these and click) to display the actions array JSON schema option
choose actions array from the schema dropdown
You can add one or more actions for each workflow trigger event. These are performed when the event occurs, and the conditions are met.
add at least one action for the workflow trigger
within the square brackets in
"actions": [ ]
type
{"
to add the curly bracket and apostrophe pair{""}
In the JSON schema dropdown, action is selected by default. This default action is to send an email
choose the action option to send an email
Each action has a JSON schema. These must be added in the defined order for the action.
add the recipients for your email
after
"send-email"
codeadd a comma and apostrophes
""
choose recipients array
add one or more recipients as a comma-separated list within the square brackets [ ] in
"recipients": [ ]
add a title for the email
after the recipients closing square bracket
add a comma and apostrophes
""
scroll down the JSON schema dropdown and choose notifications object
Notifications are added, but it has an empty value.
We need to add parameters and values for the notification. The subject, title, and body of our email notification are as follows:
,"notification": {"title": "Rejected content", "subject": "Page rejected", "body": "Please check this page and triage"}
Save the updated workflow template in the editor.
The saved workflow is formatted in a tab code.