cancel
Showing results for 
Search instead for 
Did you mean: 

Following the Groovy script -

sathish1
Champ in-the-making
Champ in-the-making
Trying to figure out why this following script is not updating the value of "creditCheckOk" variable, the setup is simple example from the "Activiti in Action"., The first step of the process is to execute this script and then execute the class., with the value that is coming from the script.,


creditCheckOk = false;
customerName = "Mr Sathish"
execution.setVariable("customerName ", "Mr Sathish");
out:println "Checking credit for " + customerName + "income" +  income  + "loanAmount " + loanAmount ;
if((income / 2) > loanAmount) {
creditCheckOk = true;
}
out:println "Checked credit for " + customerName + " outcome is " + creditCheckOk;


when I call this script from the process engine, I can see the console updating the values, but when it comes of this sequence and invokes the CreateApplicationTask class here


public class CreateApplicationTask implements JavaDelegate{
   public void execute(DelegateExecution execution){
      LoanApplication la = new LoanApplication();
      System.out.println("The value of credit check is"+ execution.getVariable("creditCheckOk"));
      System.out.println("The value "+execution.getVariable("loanAmount").getClass());
      la.setCreditCheckOk((Boolean) execution.getVariable("creditCheckOk"));
      la.setCustomerName((String) execution.getVariable("customerName"));
      la.setIncome((Long) execution.getVariable("income"));
      la.setRequestedAmount((Long) execution.getVariable("loanAmount"));
      la.setEmailAddress((String) execution.getVariable("emailAddress"));
      execution.setVariable("loanApplication", la);
   }

}


when it executes to pull the value for

      System.out.println("The value of credit check is"+ execution.getVariable("creditCheckOk")); 


this is returned as null., tght or recommendations from the community.

2 REPLIES 2

sathish1
Champ in-the-making
Champ in-the-making
Never mind, looks like variable will only be set on a groovy script when it is called out as

<code>execution.setVariable("creditCheckOk",creditCheckOk);</code>

martin_grofcik
Confirmed Champ
Confirmed Champ
Another possibility is to use:
http://www.activiti.org/userguide/#bpmnScriptTask


<scriptTask id="script" scriptFormat="JavaScript" activiti:autoStoreVariables="false/true">

Regards
Martin