cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot resolve identifier within the same activity

rajivmoghe
Champ in-the-making
Champ in-the-making
I have a process that goes as follows:

Start Process (initiator='someuser') –> Step 1 (performed by the initiator) –> Step 2 (performed by initiator's manager).
I use a userService to get the requisite values of performer, and account. The xml fragment is shown below:


    <dataObject id="initiator" name="initiator" itemSubjectRef="xsd:string">
      <extensionElements>
        <activiti:value>Filled from ReST Call</activiti:value>
      </extensionElements>
    </dataObject>

    <serviceTask id="service1" name="My Action 1" activiti:class="org.activiti.demo.MyServiceClass">
      <extensionElements>
        <activiti:field name="performer">
          <activiti:expression><![CDATA[${initiator}]]></activiti:expression>
        </activiti:field>
        <activiti:field name="suac">
          <activiti:expression><![CDATA[${userService.getAccountFor(performer, stream)}]]></activiti:expression>
        </activiti:field>
      </extensionElements>
    </serviceTask>

    <sequenceFlow id="flow4" sourceRef="service1" targetRef="service2"></sequenceFlow>

    <serviceTask id="service2" name="My Action 2" activiti:class="org.activiti.demo.MyServiceClass">
      <extensionElements>
        <activiti:field name="performer">
          <activiti:expression><![CDATA[${userService.getManagerFor(initiator)}]]></activiti:expression>
        </activiti:field>
        <activiti:field name="suac">
          <activiti:expression><![CDATA[${userService.getAccountFor(performer, stream)}]]></activiti:expression>
        </activiti:field>
      </extensionElements>
    </serviceTask>

The userService is defined as:

@Component
public class UserService {

    public String getManagerFor(String string){
       return string+"'s manager";
    }

   public int getSUAccountFor(String user, String stream) {
      System.out.println("Fetching default StreamUserAccount for "+user+" for "+stream);
      return 10;
   }
}

Question:
When invoked, the process fails in service1 with
org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'performer' 
.

What is the best way for me to pass potentially different performer for each invocation of the service task (The performer for service2 is the initiator's manager) and also get the performer-appropriate account token for the same invocation?
7 REPLIES 7

hari
Star Contributor
Star Contributor
Does your org.activiti.demo.MyServiceClass class has a variable with name "performer" of type org.activiti.engine.delegate.Expression ?

rajivmoghe
Champ in-the-making
Champ in-the-making
Yes, it does.


public class MyServiceClass implements JavaDelegate {
private Expression performer;
private Expression suac;

public void execute(DelegateExecution execution) throws Exception {
  String doer = (String) performer.getValue(execution);
  String sua = (String) suac.getValue(execution); 
  System.out.println("Performing Action call in JavaDelegate. No wait for result.");
  System.out.println("Action will be performed for "+doer+", with account "+sua);
}
}

trademak
Star Contributor
Star Contributor
Hi,

Can you include the full class, including the import statements?

Best regards,

rajivmoghe
Champ in-the-making
Champ in-the-making
Here is the class:

package org.activiti.demo;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.JavaDelegate;
//import org.springframework.stereotype.Component;

//@Component
public class MyServiceClass implements JavaDelegate {
private Expression performer;
private Expression suac;

public void execute(DelegateExecution execution) throws Exception {
  String doer = (String) performer.getValue(execution);
  String sua = (String) suac.getValue(execution); 
  System.out.println("Performing Action call in JavaDelegate. No wait for result.");
  System.out.println("Action will be performed for "+doer+", with account "+sua);
}
}

Rajiv

trademak
Star Contributor
Star Contributor
Hi,

Looking back at your BPMN XML, I think the issue is this line:

<activiti:expression><![CDATA[${userService.getAccountFor(performer, stream)}]]>

The Activiti Engine isn't able to resolve the performer variable at this point. Where did you set the "performer" variable?

Best regards,

rajivmoghe
Champ in-the-making
Champ in-the-making
Hi Tijs,

The idea is this - each of the calls to MyServiceClass needs 2 parameters - 1: the performer, and 2: his security user account (suac). I plan to pass both those to the MyService as input variables.
Now the way I approach this is as follows - in absence of anything else, the performer is the initiator. That is set using:
        <activiti:field name="performer">
          <activiti:expression><![CDATA[${initiator}]]></activiti:expression>
        </activiti:field>

With this single field everything works Ok - I can make a call.
Now to add the second variable, the security account for the performer, I use the following:
<activiti:field name="suac">
          <activiti:expression><![CDATA[${userService.getAccountFor(performer, stream)}]]></activiti:expression>
        </activiti:field>

The expectation is that the performer that has been set earlier on, will be used in the getAccountFor method…

Is this a valid expectation? if not, what is the other option, short of having a couple of script tasks to set up the appropriate variables?

jbarrez
Star Contributor
Star Contributor
yes it is, but performer and stream needs to be available BEFORE this is called as a process variable.
In your example, you are injecting it into the service task, but not setting it as a process var.