
Workflow Definition
Table of Contents [-]
To get started in creating your own workflow definitions, read our portal administration guide here:
Liferay Portal 6.0 - Administration Guide - Workflow with Kaleo
You can view sample workflow definitions in the kaleo-web plugin.
State #
Task - Action (Notifications) #
Email Notifications #
For email notifications, you can specify three template-languages: "text", "velocity" or "freemarker".
You can specify the subject of the email
Email Templates (Text) #
<actions> <notification> <name>Review Notification</name> <description>Email Subject Here</description> <execution-type>onAssignment</execution-type> <template>Email Body Here.</template> <template-language>text</template-language> <notification-type>email</notification-type> </notification> </actions>
Email Templates (Velocity & Freemarker) #
You can also generate dynamic emails in your workflow using values in the serviceContext.
Let's say you want to add email notifications in your workflow with dynamic content for the Blogs portlet. First, you will need to stuff any dynamic values that you want in the ServiceContext. Then you will need to read them from your Workflow Definition. Lastly, link the the Resource (eg: BlogsEntry, Wiki Page) to your Workflow Definition so that Resource is now using the Workflow Definition.
1) Add Values Into ServiceContext #
In your BlogsEntryLocalServiceImpl.java, you will find the following code:
WorkflowHandlerRegistryUtil.startWorkflowInstance( user.getCompanyId(), groupId, userId, ..., serviceContext);
If you want have dynamic values in your email, you can stuff values into your service/workflow context before calling WorkflowHandlerRegistryUtil.startWorkflowInstance(...., serviceContext):
// You can specify the sender in the workflow context (default sender: "'Liferay Portal Workflow Notifications [no-reply@liferay.com]'") HashMap<String, Object> workflowContext = new HashMap<String, Object>(); workflowContext.put( WorkflowConstants.CONTEXT_NOTIFICATION_SENDER_ADDRESS, "no-reply@yourdomain.com"); workflowContext.put( WorkflowConstants.CONTEXT_NOTIFICATION_SENDER_NAME, "Automated Notification Mailer"); serviceContext.setAttribute("workflowContext", workflowContext); // You can add additional values which can be used when generating the body of your notification email HashMap<String, Object> context = new HashMap<String, Object>(); context.put("value1", "[set in XLocalServiceImpl.java]"); context.put("value2", "[set in XLocalServiceImpl.java]"); // Language Keys HashMap<String, String> language = new HashMap<String, String>(); language.put("langKey1", LanguageUtil.get(Locale.US, "lang-key-1")); language.put("langKey2", LanguageUtil.get(Locale.US, "lang-key-2")); context.put("language", language); serviceContext.setAttribute("context", context); // Start Workflow WorkflowHandlerRegistryUtil.startWorkflowInstance( user.getCompanyId(), groupId, userId, ..., serviceContext);
2) Read values from the Workflow Definition #
In your Workflow Definition, you can read the values you just added by using velocity or freemarker.
Velocity Example:
<actions> <notification> <name>Creator Modification Notification</name> <description>Email Subject Here</description> <execution-type>onAssignment</execution-type> <template> <![CDATA[ #set($context = $serviceContext.getAttribute("context")) #set($language = $serviceContext.getAttribute("language")) <div>${language.langKey1}</div> <div>${context.value1}</div> ]]> </template> <template-language>velocity</template-language> <notification-type>email</notification-type> </notification> </actions>
Freemarker Example:
<actions> <notification> <name>Creator Modification Notification</name> <description>Email Subject Here</description> <execution-type>onAssignment</execution-type> <template> <![CDATA[ <#assign context = serviceContext.getAttribute("context")> <#assign language = context.language> <div>${language.langKey1}</div> <div>${context.value1}</div> ]]> </template> <template-language>freemarker</template-language> <notification-type>email</notification-type> </notification> </actions>
3) Link the the Resource to your Workflow Definition #
Control Panel -> Workflow Configuration -> Link/Assign the respective Resource and Workflow Definition.