0
votes

I have the following .bpmn2 file deployed through my alfresco workflow console with user task which will be assigned to a user according to the passed variable "Y"

 <process isExecutable="true" id="step4reconfigure41" name="Reconfigure step 4">

    <startEvent id="start"
        activiti:formKey="wf:submitAdhocTask" />
    <sequenceFlow id='flow1' 
        sourceRef='start'
        targetRef='adhocTask' />
   <userTask id="adhocTask" name="First user Task"
        activiti:formKey="wf:adhocTask">
       <documentation> First task </documentation>
       <extensionElements>
           <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
              <activiti:field name="script">
                 <activiti:string>
                  if(execution.getVariable("Y") == 22){
                     task.assignee = 'userA';
                  }
                  else if(execution.getVariable("Y") != 22){
                     task.assignee = 'userB';
                  }
                 </activiti:string>
              </activiti:field>
           </activiti:taskListener>
       </extensionElements>
    </userTask>

I successfully managed to start the process from the alfresco workflow console like:

  • start Y=22

Which was a success as the variable was successfully read and the assignment logic described in the .bpmn2 file was applied accordingly.

I want to perform the same scenario I did using the alfresco rest-api .

According to the api-explorer documentation, I have to use the /processes (POST) endpoint with a processBody like the below one

{ "processDefinitionKey": "string", "variables": { "bpm_assignee": "string", "bpm_sendEMailNotifications": true, "bpm_workflowPriority": 0 } }

I am trying to pass my variable "Y" to the processBody like this:

{ "processDefinitionKey": "test", "variables": { "Y": "5", "bpm_sendEMailNotifications": true, "bpm_workflowPriority": 0 } }

Unfortunately, even the process starts normally, the variable "Y" has not been set, which i tested through the /processes/{processId}/variables endpoint.

What should i do to perform the same action i did on my workflow console (passing the variable on start) through the rest api? And how this variable will be visible in my .bpmn2 file?

Any help would be greatly appreciated :)

2

2 Answers

1
votes

If you can't get the out-of-the-box REST API to do what you want, you can write your own Java-backed web script. The controller can use the Alfresco Workflow API WorkflowService.startWorkflow method to start the workflow and pass in the parmaeter.

The REST API might use this same API. If it does, this will probably fail to work as well. If that happens, fire up the debugger and step through the Alfresco source to see what's going on.

0
votes

Finally I managed to solve this by "expanding" the bpmnModel.xml placed on WEB-INF/lib/alfresco-repository-{version}.jar/alfresco/model/ and added an extra property inside the "bpm:startTask"

<property name="bpm:Y">
    <type>d:text</type>
</property>

Restarted server and the new process was successfully created with my new custom parameter passed set by adding to the request

{ 
      "processDefinitionKey": "test", 
          "variables": { 
                "bpm_Y": "5", 
                "bpm_sendEMailNotifications": true, 
                "bpm_workflowPriority": 0 
               }
}