cancel
Showing results for 
Search instead for 
Did you mean: 

Java Script in Activiti

larsson7
Champ in-the-making
Champ in-the-making
Good morning everyone!


I have a problem, i desinged a simple workflow where the status of webcontent ist directly converted into the approves status. But it doesn´t work. Here is my javascript that i wrote: I want to catch the ID of a User and when this user makes a post, the web content should be directly approved.

<scriptTask id="scripttask1" name="Approve" scriptFormat="javascript">
<script><![CDATA[import com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil;
import com.liferay.portal.service.UserLocalServiceUtil;

user = Packages.com.liferay.portal.service.UserLocalServiceUtil.fetchUser(10382);

roles = user.getRoleIds();
status = "Deny";
for (i = 0; i < roles.length; i++) {
if (roles == 15) {
status = "Approve";
break;
}
}

WorkflowStatusManagerUtil.updateStatus(Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.toStatus(status), workflowContext); ]]></script>
</scriptTask>

But i get the following error:

14:15:51,816 INFO [http-bio-8080-exec-5][WorkflowDefinitionManagerImpl:58] Try to deploy process DirectApprove
14:15:51,872 INFO [http-bio-8080-exec-5][WorkflowDefinitionManagerImpl:107] Process DirectApprove deployed with deployment ID 1516
14:15:51,873 INFO [http-bio-8080-exec-5][WorkflowDefinitionManagerImpl:109] 1 process definitions deployed
14:15:51,873 INFO [http-bio-8080-exec-5][WorkflowDefinitionManagerImpl:122] Process Definition Id for process process1 : process1:6:1519
14:16:02,323 ERROR [http-bio-8080-exec-7][WorkflowComparatorFactoryImpl:18] Method is not implemented
14:16:07,900 ERROR [http-bio-8080-exec-7][WorkflowComparatorFactoryImpl:18] Method is not implemented
14:16:24,158 INFO [http-bio-8080-exec-3][WorkflowInstanceManagerImpl:194] Start workflow instance process1 : 6
14:16:24,426 ERROR [http-bio-8080-exec-3][render_portlet_jsp:154] org.activiti.engine.ActivitiException: problem evaluating script: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "workflowContext" is not defined. (<Unknown source>#13) in <Unknown source> at line number 13
at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:71)
at org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior.execute(ScriptTaskActivityBehavior.java:51)


Why is workflow context undefiened??

Thanks for your help!!!

Best Regards, Philipp
10 REPLIES 10

ankit1
Champ in-the-making
Champ in-the-making
Hi,

I have enable workflow for web content using activity liferay web war & created workflow definition to enable to single approver flow which is working fine along with mail notification but just with hard coded values for mail.

I need to have dynamic values in service task for email to include values from workFlowContext and user's email
1. In email from field I need to get email id of user assigned in specific role
2. In email body display comment which was added by approval which I think its available in workflowContext but I am unable to use it in service task as it throws error.

<serviceTask id="mailtask1" name="Send Mail Notification" activiti:type="mail">
        <extensionElements>
         <activiti:field name="from" expression="test@liferay.com"></activiti:field>
          <activiti:field name="to" expression="[b]ankit@liferay.com[/b]"></activiti:field>
          <activiti:field name="subject" expression="Asset Review"></activiti:field>
          <activiti:field name="html">
            <activiti:expression>
                <![CDATA[<html><body>
                   User has submitted webcontent
                   ${serviceContext.getAttribute("articleURL")
            <p>
                                                                    [b]${workflowContext}[/b]
             Please review the webcontent waiting for you in your workflow tasks.
            <br />Assignment comment says:[b] $(taskComment)[/b] <strong>
         </p>
            <!– signature –>
            <p>Sincerely,<br /><strong>Asset Reviewer</strong></p>
          </body></html>
              ]]>
              
            </activiti:expression>
          </activiti:field>
        </extensionElements>
</serviceTask>

Can you please give some input I am sure you would have come across such needs.

awaiting for your response.


Thanks,
Ankit