« 返回到 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
  2. https://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-/ai/creating-process-definitions
0 附件
124207 查看
平均 (4 票)
满分为 5,平均得分为 3.5。
评论
讨论主题回复 作者 日期
Here's a velocity example: <actions> ... Kendal Montgomery 2011年4月11日 下午7:52
thanks kendal, I added that to the wiki article Scott Lee 2011年4月19日 上午10:55
I've updated the XML config, because the... Lars Meynberg 2011年7月28日 上午12:28
Sender mail and name in workflowContext isn't... François LE QUEMENER 2011年8月2日 上午1:47
It's a little inconvenient that... Jakub Liska 2011年11月22日 上午9:28
workflowContext.put(WorkflowConstants.CONTEXT_N... Ivano Carrara 2012年6月8日 上午10:26
More ... try to read the 6.0.6 javadoc: here:... Ivano Carrara 2012年6月9日 上午2:37
it would be extremely nice to have a property... Natasa Bulatovic 2012年7月19日 上午1:43
Hi Guys, I wonder if you guys would know how to... Jing Guo 2012年11月8日 上午9:02
Jing, in LR 6.1.1 CE GA2 there is a... Philipp Schwarz 2012年11月15日 上午11:37
CORRECTION:... Philipp Schwarz 2012年11月15日 上午11:39
Hello All.... I am using liferay version 6.1.1... Pradip A Bhatt 2013年6月25日 上午5:03
Hi Pradip, you can do this very easily with the... Scott Lee 2013年6月25日 上午10:01
The above Link... Heri Bender 2014年6月3日 下午12:46
It's actually still good, but it looks like the... Scott Lee 2014年6月3日 下午12:57
Funny, all three above links are messed up. All... Heri Bender 2014年6月3日 下午1:15
This link arrived here messed up again, this... Heri Bender 2014年6月3日 下午1:19
Ok, I went ahead and added the link to the... Scott Lee 2014年6月3日 下午2:21
In addition to the above, this code will set... Alex Swain 2015年3月17日 上午1:27

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>
在 11-4-11 下午7:52 发帖。
thanks kendal, I added that to the wiki article
在 11-4-19 上午10:55 发帖以回复 Kendal Montgomery
I've updated the XML config, because the description have to be after name not after execution-type
在 11-7-28 上午12:28 发帖以回复 Scott Lee
Sender mail and name in workflowContext isn't working on Kaleo 6.0.6.1 / Liferay 6.0.11EE
在 11-8-2 上午1:47 发帖以回复 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.
在 11-11-22 上午9:28 发帖以回复 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 ?
在 12-6-8 上午10:26 发帖以回复 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
在 12-6-9 上午2:37 发帖以回复 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.
在 12-7-19 上午1:43 发帖以回复 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?
在 12-11-8 上午9:02 发帖。
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 ...
在 12-11-15 上午11:37 发帖以回复 Jing Guo
CORRECTION: com.liferay.portal.kernel.workflow.WorkflowConstants
在 12-11-15 上午11:39 发帖以回复 Philipp Schwarz
Hello All....

I am using liferay version 6.1.1 CA GA2. I installed and used Kaleo workflow in liferay.
Kaleo provides just accept - reject states.

Now my requirement is like that i have to provide three state
1) Accept
2) Reject
3) Revise or Resubmit

So.. What i have to do??
Many friends suggests me to use JBPM.. I am very new in liferay.. I have no idea that what is JBPM.. but yes... if some one can direct me properly then i can do further.


Please Help me regarding this..
Thankssssssssssss in Advanceeeeeeeeeeee,,,,,,,,,,,

Pradip Bhatt
在 13-6-25 上午5:03 发帖。
Hi Pradip, you can do this very easily with the Kaleo workflow. In fact, all you need to do is 1) add a "Rejected State" to the sample "single-approver-definition.xml" which you can find inside the Kaleo portlet and 2) Add a transition to that new Rejected State.

Here is a very helpful reference for writing Kaleo workflow definitions:
http://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-­/ai/creating-process-definitions
在 13-6-25 上午10:01 发帖以回复 Pradip A Bhatt
The above Link "http://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-­/ai/creati­ng-process-definitions" is dead.
在 14-6-3 下午12:46 发帖以回复 Scott Lee
It's actually still good, but it looks like the URL encoding might have gotten messed up, try this: https://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-/ai/creatin­g-process-definitions
在 14-6-3 下午12:57 发帖以回复 Heri Bender
Funny, all three above links are messed up. All have somewhere a "<wbr/>&shy;" in the html source code, but all at different locations. You see this if you copy it and paste it in a text editor (or a browser's address field), where it is rendered as a "-". Who enters this "<wbr/>&shy;"? I try to paste here another - hopefully correct - version, directly copied from text editor:
http://www.liferay.com/de/documentation/liferay-portal/6.1/user-guide/-/a­i/creating-process-definitions
在 14-6-3 下午1:15 发帖以回复 Scott Lee
This link arrived here messed up again, this time the "<wbr/>&shy;" is positioned between the "...guide/-/a" and the "i/creating-...."
在 14-6-3 下午1:19 发帖以回复 Heri Bender
Ok, I went ahead and added the link to the bottom of the wiki article under "References", thanks for pointing this out.
在 14-6-3 下午2:21 发帖以回复 Heri Bender
In addition to the above, this code will set the email "from" address and name. Add it to a step before the step which sends the email as a Groovy script:

---------------------------------------------------------------------
impo­rt com.liferay.portal.kernel.workflow.WorkflowInstanceManagerUtil;
import com.liferay.portal.kernel.workflow.WorkflowInstanceManager;
import com.liferay.portal.kernel.workflow.WorkflowInstance;
import com.liferay.portal.service.WorkflowInstanceLinkLocalServiceUtil;
import com.liferay.portal.model.WorkflowInstanceLink;

ServiceContext serviceContext = (ServiceContext) workflowContext.get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT);
//This is in the portal model, not the Workflow package
WorkflowInstanceLink workflowInstanceLink = WorkflowInstanceLinkLocalServiceUtil.getWorkflowInstanceLink(companyId, groupId, className, classPK);
long workflowInstanceId = workflowInstanceLink.getWorkflowInstanceId();

//These classes actually do live in the workflow package
//Workflow instance is 'this' and where the context lives
WorkflowInstanceManager workflowInstanceManager = WorkflowInstanceManagerUtil.getWorkflowInstanceManager();
WorkflowInstance workflowInstance = workflowInstanceManager.getWorkflowInstance(companyId,workflowInstanceId);

//...a­nd the context is where the email from has been set, and will be re-set
workflowContext.put(WorkflowConstants.CONTEXT_NOTIFICATION_SENDER_ADDRESS,­"events@uea.ac.uk");
workflowContext.put(WorkflowConstants.CONTEXT_NOTIFICATION_S­ENDER_NAME,"Website Events Automated Notification");

//..update the instance with the tweaked context
WorkflowInstanceManagerUtil.updateWorkflowContext(companyId, workflowInstanceId, workflowContext);
---------------------------------------------------------------­------

Just means not having to hook classes or change the spring XML. Oh, and you can set different sender addresses for different workflows within your organisation.
在 15-3-17 上午1:27 发帖。