« Back to Workflow

Workflow Definition

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.

Task - Assignment #

Task - Transition #

References #

  1. http://www.liferay.com/community/forums/-/message_boards/message/7897645
0 Attachments
13768 Views
Average (3 Votes)
The average rating is 3.66666666666667 stars out of 5.
Comments
Threaded Replies Author Date
Here's a velocity example: <actions> ... Kendal Montgomery April 11, 2011 7:52 PM
thanks kendal, I added that to the wiki article Scott Lee April 19, 2011 10:55 AM
I've updated the XML config, because the... Lars Meynberg July 28, 2011 12:28 AM
Sender mail and name in workflowContext isn't... François LE QUEMENER August 2, 2011 1:47 AM
It's a little inconvenient that... Jakub Liska November 22, 2011 9:28 AM
workflowContext.put(WorkflowConstants.CONTEXT_N... Ivano Carrara June 8, 2012 10:26 AM
More ... try to read the 6.0.6 javadoc: here:... Ivano Carrara June 9, 2012 2:37 AM
it would be extremely nice to have a property... Natasa Bulatovic July 19, 2012 1:43 AM
Hi Guys, I wonder if you guys would know how to... Jing Guo November 8, 2012 9:02 AM
Jing, in LR 6.1.1 CE GA2 there is a... Philipp Schwarz November 15, 2012 11:37 AM
CORRECTION:... Philipp Schwarz November 15, 2012 11:39 AM

Here's a velocity example:

<actions>
<notification>
<name>Creator Modification Notification</name>
<execution-type>onAssignment</execution-type>
<descripti­on>Email Subject Here</description>
<template>
<![CDATA[
#set($context = $serviceContext.getAttribute("context"))
#set($language = $serviceContext.getAttribute("language"))

<div>${language.langKey1}</di­v>
<div>${context.value1}</div>
]]>
</template>
<template-lang­uage>velocity</template-language>
<notification-type>email</notification-type>­
</notification>
</actions>
Posted on 4/11/11 7:52 PM.
thanks kendal, I added that to the wiki article
Posted on 4/19/11 10:55 AM in reply to Kendal Montgomery.
I've updated the XML config, because the description have to be after name not after execution-type
Posted on 7/28/11 12:28 AM in reply to Scott Lee.
Sender mail and name in workflowContext isn't working on Kaleo 6.0.6.1 / Liferay 6.0.11EE
Posted on 8/2/11 1:47 AM in reply to Lars Meynberg.
It's a little inconvenient that DLAppHelperLocalServiceImpl.addFileEntry() method doesn't let you pass your custom workFlow context. It always created a new one no matter what.
Posted on 11/22/11 9:28 AM in reply to François LE QUEMENER.
workflowContext.put(WorkflowConstants.CONTEXT_NOTIFICATION_SENDER_ADDRESS, "no-reply@yourdomain.com");
workflowContext.put(WorkflowConstants.CONTEXT_NOTI­FICATION_SENDER_NAME, "Automated Notification Mailer");

The above lines cause errors... the above constants are not defined in 6.0.6

Any comments ?
Posted on 6/8/12 10:26 AM in reply to Jakub Liska.
More ... try to read the 6.0.6 javadoc: here: liferay-portal-doc-6.0.6/javadocs/com/liferay/portal/kernel/workflow/WorkflowCon­stants.html

Of course, if you follow this wiki's article you get the error: CONTEXT_NOTIFICATION_SENDER_ADDRESS cannot be resolved or is not a field
Posted on 6/9/12 2:37 AM in reply to Ivano Carrara.
it would be extremely nice to have a property that can be set-up like in portal-ext.properties or in portlet.properties for kaleo.
Posted on 7/19/12 1:43 AM in reply to Ivano Carrara.
Hi Guys, I wonder if you guys would know how to define a custom notification email subject. I've tested on it, seems only email content could use variables in it. It would be nice to have feature. So any ideas?
Posted on 11/8/12 9:02 AM.
Jing,

in LR 6.1.1 CE GA2 there is a CONTEXT_NOTIFICATION_SUBJECT member defined in com.portal.kernel.workflow.WorkflowConstants class so I gues you would be able to store custom subjects even without extending / implementing your own constants.

However I would'nt know how to read the value from the definition.xml which seems to me like witchcraft anyways ...
Posted on 11/15/12 11:37 AM in reply to Jing Guo.
CORRECTION: com.liferay.portal.kernel.workflow.WorkflowConstants
Posted on 11/15/12 11:39 AM in reply to Philipp Schwarz.