cancel
Showing results for 
Search instead for 
Did you mean: 

Importing javascript into a workflow

buje85
Champ in-the-making
Champ in-the-making
Hi,

I am trying to launch a workflow when one ends so i have written the code to launch the next workflow in a js file. I cant get the task listener to run the function in my script file.

I have looked around for ages but cant see any examples to check if I have done something stupid. I have run the import line and then called the function in the javascript console add it and everything runs fine so it is just a syntax error. This is using activiti.


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="testScriptWorkflow" name="test scripting process" isExecutable="true">
    <startEvent id="alfrescoStartevent1" name="Alfresco start" activiti:formKey="wf:submitAdhocTask"></startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <userTask id="alfrescoUsertask1" name="Alfresco User Task" activiti:formKey="wf:adhocTask">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[<import resource="/Company Home/Data Dictionary/Scripts/testingwfl.js">;testLaunch();]]></activiti:string>
          </activiti:field>
          <activiti:field name="runAs">
            <activiti:string><![CDATA[admin]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <sequenceFlow id="flow3" sourceRef="alfrescoStartevent1" targetRef="alfrescoUsertask1"></sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="alfrescoUsertask1" targetRef="endevent1"></sequenceFlow>
  </process>


can anyone help? Am I using the incorrect class?
2 REPLIES 2

kaynezhang
World-Class Innovator
World-Class Innovator
The import line should be the first line and without ";"
testLaunch(); should be in a seprate line.

buje85
Champ in-the-making
Champ in-the-making
Thanks for your help. That did the trick, I think I had the script being executing correctly before but I was getting an error as the workflow didn't like one of the lines of code in it.

In case you can help me I have made another post here. - https://forums.alfresco.com/forum/developer-discussions/other-apis/launching-workflow-within-workflo...

Thanks again.