cancel
Showing results for 
Search instead for 
Did you mean: 

Import javascript into workflow

nparry
Champ in-the-making
Champ in-the-making
When writing a workflow, can you import a javascript file from the repository into the workflow instead of actually writing it all in the xml file?  I tried something like this, but it did not work:


<script>
   <import resource="/Company Home/Data Dictionary/Scripts/someJS.js">
</script>

Thanks a lot,

Nick P
3 REPLIES 3

davidc
Star Contributor
Star Contributor
In theory, yes.  I haven't attempted this myself, so can't be sure.

Can you clarify that your code is inside:

<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
  <script>
      …
  </script>
</action>

What sort of error did you see?

nparry
Champ in-the-making
Champ in-the-making
At first I tried this:


<action name="notHiredAction" class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
   <!– This is where the javascript should be imported –>
   <script>
      <import resource="/Company Home/Data Dictionary/Scripts/someJS.js">
   </script>
</action>

And I got an error during deployment that said the "import" tag needed an end tag.  So, I added a forward slash onto the end of the tag:


<action name="notHiredAction" class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
   <!– This is where the javascript should be imported –>
   <script>
      <import resource="/Company Home/Data Dictionary/Scripts/someJS.js" />
   </script>
</action>

I then got the error from graph.def.GraphElement:


action threw exception: Script expression has not been provided.

It looks like it's just not evaluating the "import" tag.  That's why I thought it might just be a syntax problem….

davidc
Star Contributor
Star Contributor
Wrap your script in a CDATA block e.g.

        <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
              <expression>
                 <![CDATA[                
                    <import resource="/Company Home/Data Dictionary/Scripts/test return value.js">
                 ]]>
              </expression>
              <variable name="theresult" access="write" />
            </script>
         </action>