Applying workflow on custom assets in Liferay 6 through plugins

As you know, Liferay 6 integrates workflow system like jBPM or Kaleo on any assets finally. By this feature, users are able to manage the content creation process with a workflow. Out-of-the-box, liferay 6 provides the ability to enable workflow for core assets:

  • Blogs Entry
  • Comments
  • Document Library Document
  • Message Boards Message
  • Web Content
  • Wiki Page

Logically, worklow is available for any assets (Out of box entities).For more details, you can refer to blogs Liferay Workflow In Action and Applying workflow on any assets in Liferay 6.

Asset here refers to Liferay core content entities (generated by Service-Builder in portal core) and custom entities (generated by Service-Builder in plugins): like Document Library document, Image Gallery image, Message Boards message, Web Content, Wiki page, comments, Blogs entry. Logically, workflow should be available for any assets like Image Gallery image, Calendar event, layout page, Bookmarks entry, user, organization, etc. (Abstracted from the book: Liferay Portal 6 Enterprise Intranets)

Most importantly, you can apply workflow systems on custom assets in Liferay 6 through plugins. This article will show you how to apply workflow on custom assets (generated by Service-Builder) in Liferay 6 through plugins. Here I use custom assets knowledge base articles as examples in Liferay Portal 6.0.5 GA3.

How does it work?

You can simply download WAR from

knowledge-base-portlet-6.0.6.1.war

and deploy it

Configure workflow on any custom assets

Now you can configure workflow now. I use custom asset Knowledge base Article as an example.

Create two users: David Berger – a content creator; Lotti Stein – a content reviewer. And assign them as members of community Guest.

Login as admin and go to Control panel | Liferay.com| Workflow Configuration

Locate Knowledge Base Artcile and select “Single Approver” workflow and save it.

Go to Control panel | Portal| Communities and assign user roles of community guest; note that you can apply workflow on any assets of any groups (communities and organizations). Here I use the group Guest as an example.

Assign roles (community or organization content reviewer – Auto-generated role from workflow definition) to users (David Berger and Lotti Stein).

Go through workflow

Assign proper permissions to users David Berger and Lotti Stein that they can manage pages and create Knowledge Base articles in community Guest;

Login as David Berger and create Knowledge Base article called “Liferay Portal 6 Enterprise Intranets”; you would see that the asset Knowledge Base article goes workflow and it states as “Pending”;

 Login as Lotti Stein and go to Control Panel | Lotti Stein | My Workflow Tasks; you would see tabs: Assigned to Me, Assigned to My Roles, My Completed Tasks. Under the tab Assigned to My Roles, you would see the workflow task “Liferay Portal 6 Enterprise Intranets” with Asset Title “Liferay Portal 6 Enterprise Intranets” and Asset Type “Knowledge Base Article”.

Now you can review task or assign task to somebody. Click on the workflow task and assign this to yourself “Lotti Stein”; and add comment “Please review”; as you can see, the workflow task is moved to the tab “Assigned to Me”;

 Click on the workflow task under the tab “Assigned to Me”; and you can either reject it or approve it; you can click on “Approve Asset” and add comment “looks good” as well;

As you can see, the workflow task is move to the tab “My Completed Tasks”. In the detail view of the task, you can view and edit the content, read the recent activity of the task, view the status and change its status, add comments, etc.

After approved, Knowledge Base  article“Liferay Portal 6 Enterprise Intranets” would be visible for end users.

Summary

As you can see, you could be able to apply workflow on any custom assets generated by Service-Builder in Liferay 6. The asset Knowledge Base article is one of them (custom assets).

Your comments or suggestions?

How to make it?

You should be able to apply workflow on any custom assets in Liferay 6 or above version. How to make it through plugins? I will address programatic details in next blogs post. 

Blogs
What makes it nice is that, from workflow integration perspective, there is no difference between Liferay core asset and custom asset. You can also define your own workflow process and apply it to Liferay core assets or your custom assets.
Thanks, Jonas.I am looking forward to your next blogs post of programatic details.
Nice article. Has anyone tried to decipher how single-workflow-definition.xml work? how to interprete the flow in xml itself so that new workflow.xml can be created.
Hello Jonas,

Thanks once more. Are we expecting your next blog on workflow programatic details soon. Eager to try it out.
@Pius @Gu,
Thanks. Yes, the next blog on workflow programmatic details - "How to add workflow capabilities on Knowledge Base articles or any custom assets in plugins" - is on the way. It should be ready tomorrow.
Thanks, looking forward to it. Meanwhile, may I ask two quick question:
1. In the workflow, can the approval process be routed to another user (e.g. the immediate manager of the originating user) apart from the routing to people that have roles indicated in the workflow definition?
2. Is there escalation support yet?

Thanks.
Hi Pius, Thanks.

The new blog is here: http://www.liferay.com/web/jonas.yuan/blog/-/blogs/how-to-add-workflow-capabilities-on-knowledge-base-articles-or-any-custom-assets-in-plugins.

>> 1. In the workflow, can the approval process be routed to another user (e.g. the immediate manager of the originating user) apart from the routing to people that have roles indicated in the workflow definition?

Yes, you can.

>> 2. Is there escalation support yet?

The users can withdraw the tasks of workflow process anytime. Does it answer your question?
Thanks Jonas. I will take a close look at the new blog.

Regarding my first question, it's good to know that specifying users instead of roles is supported. Kindly send a quick example of assigning tasks to users rather than roles. The sample workflow definitions so far use roles (community, organization, regular) .

The second question has to do with timing of tasks. If a given user assigned a task does not execute it within a given period, it should be transferred automatically to another indicated user if the period of grace expires.

Thanks once more.
Thank you, Pius. Current workflow systems in Liferay 6 should cover these two features in nature. But I do not think this kind of workflow definition exist at moment.

Let me go back, check capabilities of workflow specification and definition, and come back to you as early as possible.
nice article. one question is how can we difine new definitions adn use it on custom protlets. Is there any article on this. Can you please send the link?

Also the defintions in liferay 5.2.3 wont work here (Eg. Holiday definition). How can that be achived? Please help
Hi Geervani, Thanks. the workflow feature (with jBPM or Kaleo) is used for 6.0 or above version only. 5.2 has different workflow architecture integration.

We do need doc for new workflow definition. Hope that I could post another article shortly.
Hi Jonas,

Thanks for the quick response.
My actual requirement is something like this.

I need to develop a portlet for employee leave management. Employee details is obtained from SAP BAPI's. I need to integrate Liferay workflow for leave approval. Once approved the SAP bapi function should be called to update other details. can this be achieved with Liferay 6.0 workflow? can you please share some reference/links to work on this. Any help will highly appreciated.

Thanks in advance

Geervani
Hi Geervani, Thanks

You may take two-step approach
1) create a SAP portlelt with custom content model
2) apply workflow on custom content model.

Liferay 6 would be able to satisfy this requirement.
Thanks Jonas,
I have a question. Is it possible to add/display 'My Workflow task' in a normal page(rather than control panel)? 'My Workflow task' portlet in found in portlet-display.xml in the hidden category. I changed it to admin category. But unable to see that in admin category. Please help.
Thanks
geervani
Hi Geervani,

see this:

http://www.liferay.com/community/forums/-/message_boards/message/6089631

There is the answer.

Bye
Hi Geervani, sorry to come back to you late.

By default, portlets: 150 - Workflow Tasks and 153 - My Workflow Tasks are hidden.

You can make them visible by removing them from category category.hidden in liferay-display.xml.

Thanks to Unai, you can find the same at
http://www.liferay.com/community/forums/-/message_boards/message/6089631

Hope that it helps,

Thanks

Jonas
Hi Jonas,

I am testing the Kaleo workflow available in the public repository (branch). There is an important bug which I have flagged (http://issues.liferay.com/browse/LPS-15197). I think it will be better to fix that bug which is not currently listed in the todo list before the imminent release.

Thanks,
Pius
Nice! thank you Pius.
Thanks for the feedback. One more observation...

I get the impression that additional portal instances are neglected in testing as development on workflow proceeds both for the 6.0.6 branch (http://issues.liferay.com/browse/LPS-15197) as well as for the trunk (http://issues.liferay.com/browse/LPS-15101) . Does this imply that the multi-instance feature of Liferay is not given due consideration? In my opinion, it is a major distinguishing feature of Liferay and therefore, new major features like workflow ought to be tested continuously on additional portal instances as development proceeds just as it is done with the default instance. Kindly convey the message.

Thanks.
Pius
Good catch, thanks Pius!
hi,
I am a beginner in the world of Liferay
how to deploy knowledge-base-portlet-6.0.6.1.war,
I know it's a stupid question but please help me
hi,
I am a beginner in the world of Liferay
how to deploy knowledge-base-portlet-6.0.6.1.war,
I know it's a stupid question but please help me
Hi Jonas,

Do you know where can I find a guide or any doc about the possibilities of Kaleo?

I would like to add a conditional node to my workflow def, but I have no Idea how and I can't find any information about it...

Thanks in advance
Hi Unai, you may use another workflow: Workflow assets must be approved first by Marketing and then by Legal.

http://www.liferay.com/c/document_library/get_file?p_l_id=5624309&groupId=31578&folderId=6185795&name=DLFE-76603.xml

For somehow details, you may refer to online doc.
http://www.liferay.com/documentation/liferay-portal/6.0/administration/-/ai/workflow-with-kaleo

Hope that it helps,

Thanks,

Jonas
Hi Jonas,

I created a custom portlet and added workflow capabilities for that. It got added. I have configured to use Single Level Approver Workflow. When I submit data from the portlet it is showing in 'My Submissions' in 'Control Panel'. I assigned to 'Content Reviewer' and 'Content Reviewer' is able to see in 'My Workflow Task'. Problem is when I click on 'Review', nothing happens. I page will just get refreshed. Its not getting redirected to Review Screen. Am I missing something.
Also the asset Title in 'My Workflow Task' is displaying as null and in Asset Type I can see class name.

Please help on this. How to display review screen on click on Review link?

I followed the steps in http://www.liferay.com/web/jonas.yuan/blog/-/blogs/5786756/maximized

Thanks & Regards
Sandhya
Hi,

I am using liferay workflow 6.0.5. When I configure a worflow for a custom portlet I am getting screen like this. The Asset Tile is null. Also When I click on review it is redirecting to a blank page and i am not able to see content of the portlet.




please help. Its very urgent

Thanks
Hi Sandhya, Would you be able to share your settings or configuration of Workflow on your custom portlet?

It would help if you could narrow down the issue.
Thanks jonas for the reply. I am using the default 'Single Approver' workflow for the portlet. I created the normal portlet and added workflow for that. I followed Knowledge Base.
Hi Sandya, Thanks.

Does workflow work well in your Konwledge base portlet?
Hi Jonas,

Glad to here from you back. I had almost started feeling liferay 6.0.5 workflow was a wrong choice.

Ny the way answer to your question is No. When i try to use KB it says temporarily unavailable.
I am not able to add KB article portlet.
Is the review click event somehow related to Workflow asset type title? Where to set that? For me its null. my portlet is for an 'HRMS module leave approval' and doesn't have a title field. But to check i just hard coded title.

Waiting for your response.

Thanks
Hi Sandhya, No sure about issue you got. You may use Liferay 6.0 EE. Here you may test workflow on KB of Liferay 6.0 EE,
at http://xxx.xxx.com/

jonas/jonas

Please let me know your test,

Thanks

Jonas
Thank you,

i logged in to your demo site and tried to add article in Control panel , KB Admin. It is rediring to http://ldapds.cignex.com/group/control_panel/null and giing not found error.

One more thing is with the exising CE i am able to work with Wiki, blog etc even if i configure workflow.
I think i am missing something.

regards
Sandhya
HI Sandya, sorry that the server has null issue -emoticon (I am planning to fix it later).

Anyway, the workflow works in my side for 6.0 EE. If possible, you may try workflow in 6.0 EE. 6.0.5 CE should work with bugs.

Thanks
No We dont have EE. We chose Liferay because if free.

Anyway thanks for you reply.
Hi Sandhya, you may use 6.1 trunk version, where a set of bugs related to workflow got fixed.
Hi Juan,

finally got that working. I was missing adding to "assetEntry". I have one more question. In a leave request approval, i want to assign the workflow task directly to the manager of the applying employee (instead of a role called manager). I tried something like this in my localserviceimpl:

WorkflowInstanceLink wfinl;
wfinl = workflowInstanceLinkLocalService.getWorkflowInstanceLink(user.getCompanyId(), groupId, LeaveDetails.class.getName(), leavedetails.getResourcePrimKey());

long wfinstanceid = wfinl.getWorkflowInstanceId();
List<WorkflowTask> lstwft;
int end = WorkflowTaskManagerUtil.getWorkflowTaskCountByRole(user.getCompanyId(), 17503, Boolean.FALSE);
lstwft = WorkflowTaskManagerUtil.getWorkflowTasksByRole(user.getCompanyId(), 17503, Boolean.FALSE, 0, end, null);
for (int i = 0; i < lstwft.size(); i++) {
WorkflowTask wft = lstwft.get(i);
long wftid = wft.getWorkflowTaskId();
WorkflowTaskManagerUtil.assignWorkflowTaskToUser(user.getCompanyId(), 10892, wftid, 10892, "Assign", null, null);
}

but getting some exception in the last line while calling the method assignWorkflowTaskToUser . can you please help on this.

Thanks
Sandhya
Hi Jonas,

One thing i find out while debugging is, If I login as "Bruno Admin", the above code works perfectly. Other wise i is throwing some permission exception. while reading your blog I found the following lines "Assign proper permissions to users David Berger and Lotti Stein that they can manage pages and create Knowledge Base articles in community Guest;". Where do do this?

regards
sandhya
Hi Sandhya, sorry to come back to you late.

Do you get your questions answered?
Thanks Jonas, Yes Its working now. But I still have a problem with liferay workflow. If I include <asset-renderer-factory> or <workflow-handler> tags in liferay-portlet.xml (which is a must for implementing LR workflow)for the custom portlets that i have developed, I am getting the Null pointer exception when deploying the portlet. Error says: "Error Registering portlet". There is already issues logged in JIRA for this. But I dont knw how to resolve. I am using Tomcat Bundle.

Please advise
Hi Sandhya, thanks. Are you able to paste your configuration here? Thus you would get helps in time.
Hi Jonas,

configurations in liferay-portlet.xml is as follows

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.0.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_0_0.dtd">
<liferay-portlet-app>
<portlet>
<portlet-name>TimeAccount</portlet-name>
<asset-renderer-factory>com.liferay.portlet.hrms.asset.LeaveAssetRendererFactory</asset-renderer-factory>
<workflow-handler>com.liferay.portlet.hrms.workflow.LeaveWorkflowHandler</workflow-handler>
<instanceable>true</instanceable>
<ajaxable>true</ajaxable>
</portlet>
</liferay-portlet-app>


and config in portlet xml is

<?xml version='1.0' encoding='UTF-8' ?>
<portlet-app xmlns='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd' version='2.0'>
<portlet>
<description>TimeAccount</description>
<portlet-name>TimeAccount</portlet-name>
<display-name>TimeAccount</display-name>
<portlet-class>com.liferay.portlet.hrms.TimeAccount</portlet-class>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
<portlet-mode>EDIT</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<resource-bundle>com.liferay.portlet.hrms.messages</resource-bundle>
<portlet-info>
<title>TimeAccount</title>
<short-title>TimeAccount</short-title>
</portlet-info>
</portlet>
</portlet-app>


Please advise.

thanks
sandhya
Hi Sandhya, thanks. Sorry to come back to you late. The XML files look good in general. you may disable following two lines.

<instanceable>true</instanceable>
<ajaxable>true</ajaxable>

Hope that it helps.
Hi Jonas,

I am using LR tomcat bundle 6.0.5. I have developed few custom portlets and enabled workflow for that. everything's fine till now. I want to display records in 'my workflow task' and 'my submission' in descending order(i.e. recent most record on top). How can I do this without changing the source(as I am using tomcat bundle). Can we change something in jsp or jspf to achieve this? Please advise.

Thanks in advance
Regards,
Sandhya
One more question,

Present we are using role based workflow with manager and employee roles. If we have to use user-based workflow, is it necessary to hard-code the screen-name, email-id etc. in the workflow definition XML or can that be generalized. Is there any doc. on user based workflow definition for LR 6.0.5?
Please advise

Thanks
Sandhya
Not in need. Current workflow is defined as role-based workflow, but the UI is user-based. Is this what you are looking for?
Hi Jonas,

Just wondering if Kaleo workflow works well for other people in additional portal instances with shard enabled. The bugs I earlier flagged for 6.0.6 (http://issues.liferay.com/browse/LPS-15197) and 6.1.0 (http://issues.liferay.com/browse/LPS-15101) still persist and there seem to be nobody else interested in the issues I raised. Is it something you can try out?

Thanks.

Pius
Hi Pius, thanks. It seems that these two tickets didn't get reviewed in time. Sorry about this bad news.

These two issues may get fixed in EE version - need to test it out.

By the way, do you use EE version?

Jonas