0
votes

I am doing a custom notification for Reviewer, Administrator, any one can help me to figure it out what's wrong in my kaleo workflow?

Here's the requirements

  • The Administrator can create a new account for the user for security purposes.
  • The Reviewer (like as admin but only priviledge is to review, approve, and reject request from admin and users) all create new account from admin must be review if approve or not by the Reviewer before created new account from the admin

Flow:

  1. Admin create an account for new user then
  2. Notify the Reviewer to review the request from the admin then
  3. A. if the Reviewer reject the application request, notify the admin to resubmit for update.
  4. B. if the Reviewer approve the application request, notify the admin to know that request is approved.
  5. Done

Problem is 1 to 3 is working but in 4 after reviewer approved the application, admin did'nt receive notification

here is my code

<?xml version="1.0" encoding="UTF-8"?><workflow-definition xmlns="urn:liferay.com:liferay-workflow_6.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:liferay.com:liferay-workflow_6.2.0 http://www.liferay.com/dtd/liferay-workflow-definition_6_2_0.xsd">
<name>custom-mrcos-notify</name>
<version>1</version>
<state>
    <name>created</name>
    <metadata>
        <![CDATA[{"transitions":{"review":{"bendpoints":[]}},"xy":[30,30]}]]>
    </metadata>
    <initial>true</initial>
    <transitions>
        <transition>
            <name>review</name>
            <target>review</target>
        </transition>
    </transitions>
</state>
<task>
    <name>update</name>
    <metadata>
        <![CDATA[{"transitions":{"resubmit":{"bendpoints":[[303,140]]}},"xy":[260,220]}]]>
    </metadata>
    <actions>
        <action>
            <name>reject</name>
            <script>
                < ![CDATA[
                Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus(Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.toStatus("denied"), workflowContext);
                Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus(Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.toStatus("pending"), workflowContext);]] >
            </script>
            <script-language>javascript</script-language>
            <execution-type>onAssignment</execution-type>
        </action>
        <notification>
            <name>Creator Modification Notification</name>
            <template>Your submission was rejected by ${userName}, please modify and resubmit.</template>
            <template-language>freemarker</template-language>
            <notification-type>email</notification-type>
            <notification-type>user-notification</notification-type>
            <execution-type>onAssignment</execution-type>
        </notification>
    </actions>
    <assignments>
        <user>
            <email-address>r@liferay.com</email-address>
        </user>
    </assignments>
    <transitions>
        <transition>
            <name>resubmit</name>
            <target>review</target>
        </transition>
    </transitions>
</task>
<task>
    <name>review</name>
    <metadata>
        <![CDATA[{"transitions":{"approve":{"bendpoints":[[354,82]]},"reject":{"bendpoints":[]}},"xy":[160,30]}]]>
    </metadata>
    <actions>
        <notification>
            <name>Review Notification</name>
            <template>${userName} sent you a ${entryType} for review.</template>
            <template-language>freemarker</template-language>
            <notification-type>email</notification-type>
            <notification-type>user-notification</notification-type>
            <execution-type>onAssignment</execution-type>
        </notification>
        <notification>
            <name>Review Completion Notification</name>
            <template>Your submission has been reviewed and the reviewer has applied the following ${taskComments}.</template>
            <template-language>freemarker</template-language>
            <notification-type>email</notification-type>
            <recipients>
                <user />
            </recipients>
            <execution-type>onExit</execution-type>
        </notification>
    </actions>
    <assignments>
        <user>
            <email-address>r@liferay.com</email-address>
        </user>
    </assignments>
    <transitions>
        <transition>
            <name>reject</name>
            <target>update</target>
            <default>false</default>
        </transition>
        <transition>
            <name>approve</name>
            <target>Approved</target>
        </transition>
    </transitions>
</task>
<state>
    <name>approved</name>
    <metadata>
        <![CDATA[{"xy":[740,100]}]]>
    </metadata>
    <actions>
        <action>
            <name>approve</name>
            <script>
                < ![CDATA[
                 import com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil;
                 import com.liferay.portal.kernel.workflow.WorkflowConstants;
                 WorkflowStatusManagerUtil.updateStatus(WorkflowConstants.toStatus("approved"), workflowContext);]] >
            </script>
            <script-language>groovy</script-language>
            <execution-type>onEntry</execution-type>
        </action>
    </actions>
</state>
<task>
    <name>Approved</name>
    <metadata>
        <![CDATA[{"transitions":{"Ok":{"bendpoints":[]},"ok":{"bendpoints":[]}},"xy":[470,30]}]]>
    </metadata>
    <actions>
        <notification>
            <name>notify-approved</name>
            <template>The application of ${entryType} is approved by ${userName}.</template>
            <template-language>freemarker</template-language>
            <notification-type>email</notification-type>
            <execution-type>onAssignment</execution-type>
        </notification>
        <action>
            <name>approved</name>
            <script>
                < ![CDATA[ 
                import com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil;
                import com.liferay.portal.kernel.workflow.WorkflowConstants;
                 WorkflowStatusManagerUtil.updateStatus(WorkflowConstants.toStatus("approved"), workflowContext);
                ]] >
            </script>
            <script-language>groovy</script-language>
            <execution-type>onEntry</execution-type>
        </action>
    </actions>
    <assignments>
        <user>
            <email-address>test@liferay.com</email-address>
        </user>
    </assignments>
    <transitions>
        <transition>
            <name>Ok</name>
            <target>approved</target>
        </transition>
    </transitions>
</task>

Note my code given above is for kaleo workflow.

2
If you create a custom Kaleo workflow, then LR would not sent the notifications. You have to make some customization in Liferay code to send the notification for custom workflow.aston
@aston That's not true. I have used to create very complicated workflow definitions, and all notifications were successfully managed in part of its xml definition, this has nothing with Liferay code at all. Sometimes of course you need to use some part of code as script in defintion but that's a different cup of tea.tomic

2 Answers

2
votes

I managed to configure single approver workflow to work exactly with your scenario which use notification of users when Documents has been approved. One change I applied to default workflow definition was adding part of notification to approved state. Here is part of code:

    <state>
    <name>approved</name>
    <metadata>
        <![CDATA[{"xy":[380,51]}]]>
    </metadata>
    <actions>
        <action>
            <name>approve</name>
            <script>
                <![CDATA[import com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil;
                                                                        import com.liferay.portal.kernel.workflow.WorkflowConstants;
                    WorkflowStatusManagerUtil.updateStatus(WorkflowConstants.toStatus("approved"), workflowContext);]]>
            </script>
            <script-language>groovy</script-language>
            <execution-type>onEntry</execution-type>
        </action>
        <notification>
            <name>Creator Approval Notification</name>
            <template>Your submission was accepted by ${userName}.</template>
            <template-language>freemarker</template-language>
            <notification-type>user-notification</notification-type>
            <recipients>
                <user/>
            </recipients>
            <execution-type>onExit</execution-type>
        </notification>
    </actions>
</state>

Add similar part of notification to your approved node. From other hand I am not sure if you really need another node Approved before approved state at all.

0
votes

I would give a try to change execution-type from:

<execution-type>onAssignment</execution-type>

to

<execution-type>onEntry</execution-type>

in last part of task Approved

Following documentation:

Sending notifications Notifications need an execution-type which can be onAssignment, onEntry or onExit.

  • onAssignment generates and sends the notification when the user is assigned the task in the workflow. Note: onAssignment notification
    will not work if you wish to notify a user that is not part of the
    workflow.

  • onEntry generates and sends the notification when entering the workflow task or state.

  • onExit generates and sends the notification when exiting the workflow task or state.