cancel
Showing results for 
Search instead for 
Did you mean: 

How to include javascript in processdefinition file

sanatmastan
Champ in-the-making
Champ in-the-making
HI,

can anyone help me how to include external javascript file in processdefinition file and reuse existing js code?

Thanks
Sanat.
10 REPLIES 10

sanatmastan
Champ in-the-making
Champ in-the-making
Any suggestions pls??????

msvoren
Champ in-the-making
Champ in-the-making
   <script>
      &lt;import resource="/Company Home/Data Dictionary/Scripts/my_wf_logic.js"&gt;
      someFunction(bpm_package.children[0]);
   </script>

sanatmastan
Champ in-the-making
Champ in-the-making
Hi,

my myworkflow.js contains

function myalffun(var1)
{
   return var1;
}

in one of transitions in my processdefinition.xml i included js as follows:

……
   <transition name="approve" to="l10_content_authoring" >
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
            <import resource="/Company Home/Data Dictionary/Scripts/myworflow.js"/>
                                  <expression>
               logger.log(bpm_package.children[0].url);
               logger.log(myalffun('sanat'));
            </expression>   
          </script>
      </action>
   </transition>
…..

Even now i am not able to access "myalffun" Please help me in sorting out this problem.

Thanks
Sanat.

msvoren
Champ in-the-making
Champ in-the-making
<transition name="approve" to="l10_content_authoring" >
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
&lt;import resource="/Company Home/Data Dictionary/Scripts/myworflow.js"/&gt;
logger.log(bpm_package.children[0].url);
logger.log(myalffun('sanat'));
</script>
</action>
</transition>

sanatmastan
Champ in-the-making
Champ in-the-making
hi i tried executing my workflow incorporating your changes, but i am getting following error

is the logger not an javascript object? shouldnt we require logger statement to be wrapped inside <expression> tag?
like
<expression>
logger.log(bpm_package.children[0].url);
logger.log(myalffun('sanat'));
</expression>

Please suggest…

17:23:10,386 User:content_author1 ERROR [graph.def.GraphElement] action threw exception: Script expression has not been provided
org.alfresco.service.cmr.workflow.WorkflowException: Script expression has not been provided
        at org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript.execute(AlfrescoJavaScript.java:123)
        at org.jbpm.graph.def.Action.execute(Action.java:122)
        at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:264)
        at org.jbpm.graph.def.GraphElement.executeActions(GraphElement.java:220)
        at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:190)
        at org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:174)
        at org.jbpm.graph.def.Transition.take(Transition.java:138)
        at org.jbpm.graph.def.Node.leave(Node.java:394)
        at org.jbpm.graph.node.TaskNode.leave(TaskNode.java:209)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

msvoren
Champ in-the-making
Champ in-the-making
No, don't think so. Move logger code to included js function.
Paste your processdefinition, maybe that will tell us something more.

Matija,
Mobitel Business Solutions

norgan
Champ in-the-making
Champ in-the-making
You need the expression tags, if you are using the var tags. But then, I guess, the "import" statement would need to be inside th expression tag as well.

Norgan

sanatmastan
Champ in-the-making
Champ in-the-making
Hi,
finally i am able to attach external javascript inside workflow processdefintion, here are my processdefinition and js files.

My processdefinition.xml
<?xml version="1.0" encoding="utf-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="ppdwfSmiley TongueaypalDocumentWorkflowGroupAssignee_test">
   <event type="process-end">
      <script>
      System.out.println("———- Process End————");</script>
   </event>
   <event type="process-start">
      <script>System.out.println("———- Process Start————");</script>
   </event>

  <swimlane name="initiator" />
  <swimlane name="content_reviewer">
    <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
      <pooledactors>#{ppdwf_grp_content_approver_association}</pooledactors>
    </assignment>
  </swimlane>
  <swimlane name="l10_content_author">
    <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
      <pooledactors>#{ppdwf_l10_grp_content_author_association}</pooledactors>
    </assignment>
  </swimlane>
 
  <start-state name="start">

    <event type="node-enter">
      <script>System.out.println("———- Node Enter of start Task ————");</script>
    </event>

    <task name="ppdwf:startTaskGrpAssignee" swimlane="initiator" />
   <transition name="initiate" to="review" />
  </start-state>
 
  <task-node name="review">
      <event type="node-enter">
      <script>System.out.println("———- Node Enter of review Task ————" );</script>
      
    </event>
    <event type="node-leave">
      <script>System.out.println("———- Node Leave of review Task ————" );</script>
    </event>

    <task name="ppdwf:contentReviewerTask"  swimlane="content_reviewer" />
    <transition name="approve" to="l10_content_authoring" >
      <!–  Copy the content to approve folder and to l10 draft folder –>
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
            &lt;import resource="/Company Home/Data Dictionary/Scripts/myworflow.js"&gt;
            calllogger();
            logger.log(myalffun("sanat3"));
          </script>
      </action>
   </transition>
  </task-node>
 
   <task-node name="l10_content_authoring">
      <task name="ppdwf:l10contentAuthorTask"  swimlane="l10_content_author" />
      <transition name="taskdone" to="end" />
      <transition name="reject" to="review" />
   </task-node>
 
 
  <end-state name="end" />
</process-definition>



javascript is uploaded under /Company Home/Data Dictionary/Scripts/myworflow.js
function myalffun(var1)
{
   return var1;
}

function calllogger(){
logger.log(myalffun('sanat2')+bpm_package.children[0].name);
}

hyperation
Champ on-the-rise
Champ on-the-rise
Hi sanatmastan,

For your processdefinition, does having Java code in the <script> tags work?  If so, where does the print lines show up?

Thanks
Smiley Happy