Maestro How-To: Fire a Workflow After Saving Content with Rules
A very common use-case for Maestro is to launch a workflow in order to moderate some piece of content. You may have an expense form as a content type and you wish to have a manager review and approve it before handing it off to other departments for processing.
This post will show you how to fire off a moderation workflow after saving content with Rules.
Step 1: Create a simple test flow
I know you have a super-ultra-complex workflow, but this is best to get off the ground with a simple 1 step flow for the time being!
As shown, this is a simple 1 step flow to ensure that you're getting all of the mechanics to work. This is an interactive function task with the handler set to "maestro_show_message".
When you're editing the interactive function task, go to the "Optional" tab, and create a variable named "message" and type in a simple message for its value. This will be a simple placeholder so the task actually does something in the task console.
Assign the task to a user that has rights to view and edit Article content. Using the Admin user is fine for this example to avoid permission problems for the time being. You also will have to create a new process variable for this workflow.
As you can see, this variable is called "node_id" and will be used to store the created node's ID inside of the process after it has been created.
Step 2: Create a new rule
I trust that you know how to create rules. When you create the rule, ensure that you create it based on the event of firing after saving of new content. Create a rule condition to only fire the rule when a certain type of content is created. In my example, I'm using the default Article content type that comes out-of-the-box with Drupal.
At this point, the rule will fire any time a new Article is created.
Step 3: Rule Actions
What's most important about this step is to get the newly created node automagically added to a Maestro workflow.
We need to do this by associating the node's ID with the node_id process variable we created in step 1. You do this by first creating an action to "Add a variable". It must be an integer value, and the variable label and variable name should be "node_id". Maestro will look for these specifically named rules variables in order to try to set its own "node_id" variable from step 1.
Next, create a second action that will "Set a data value". You will set the newly created node_id rule variable with the created content's node:nid.
Finally, you will create a third action to "Launch a Maestro Workflow". In the value drop down, select the workflow you wish to launch. In Step 1, I named ours "Rules based workflow". Check off the "Content Moderation Workflow" checkbox as that will allow Maestro to pre-populate some of the internal Maestro data elements with content linkages. The Process ID section should simply have "Process ID" as the variable label and "process_id" as the variable name.
Your Actions should look similar to this:
At this point, you've created a rule that will pass off node information to Maestro and launch a workflow.
Here's a sample of what my task console looks like when I created an article.
As shown, the task console has a flow created that has a single task. When you expand the task details, you will see the Article content type listed under the Content area. If you have permissions to view/edit, you can click on the content link to the Article and view it.