AnsweredAssumed Answered

creditCheckOk variable not set in DelegateExcution variable

Question asked by sonam on Oct 17, 2014
Latest reply on Oct 21, 2014 by jbarrez
I am working on chapter 5 from Activiti In Action on deploying the bar file in Activiti Explorer.  Prior to deploying I ran the LoanRequestTest.java file.    The Activiti Explorer is connected to a in-memory database. 

After deploying the loanrequest.bar file in Activiti Explorer, I signed-in as Fozzie.  However, after filling out the form with "Miss Piggy" and on clicking the "Start Process" I ran into an error where the "creditCheckOk" variable is never set in the (CreateApplicationTask.execute(DelegateExecution execution)) DelegateExecution variable from the Groovy scriptTask.  I printed the execution variable map contents and it has this (without the creditCheckOk variable set) :

execution variables are {loanAmount=400, income=1000, name=Miss Piggy, emailAddress=miss.piggy@localhost}


The following is the process xml file contents:

<process id="loanrequest" name="Process to handle a loan request">
    <startEvent id="theStart">
      <extensionElements>
        <activiti:formProperty id="name" name="Name" required="true" type="string" />
        <activiti:formProperty id="emailAddress" name="Email address" required="true" type="string" />
        <activiti:formProperty id="income" name="Income" required="true" type="long" />
        <activiti:formProperty id="loanAmount" name="Loan amount" required="true" type="long" />
      </extensionElements>
    </startEvent>
    <sequenceFlow sourceRef="theStart" targetRef="checkCredit" />
      <scriptTask id="checkCredit" scriptFormat="groovy">
         <script>
            out:println "Checking credit for " + name;
            creditCheckOk = false;
            if((income / 2) > loanAmount){
               creditCheckOk = true;
            }
            out:println "Checked credit for " + name + " outcome is " + creditCheckOk;
         </script>
    </scriptTask>
    <sequenceFlow sourceRef="checkCredit" targetRef="createApplication" />
    <serviceTask id="createApplication"   activiti:class="org.bpmnwithactiviti.chapter5.CreateApplicationTask" />
    <sequenceFlow sourceRef="createApplication" targetRef="evaluateLoanRequest" />
    <userTask id="evaluateLoanRequest" name="Evaluate loan request" activiti:assignee="fozzie">
      <extensionElements>
        <activiti:formProperty id="customerName" name="Customer name" expression="${loanApplication.customerName}" writable="false"/>
        <activiti:formProperty id="income" name="Income of customer" expression="${loanApplication.income}" writable="false"/>
        <activiti:formProperty id="requestedAmount" name="Requested loan amount" expression="${loanApplication.requestedAmount}" writable="false"/>
        <activiti:formProperty id="creditCheckOk" name="Outcome of credit check" expression="${loanApplication.creditCheckOk}" writable="false"/>
        <activiti:formProperty id="requestApproved" name="Do you approve the request?" required="true" type="enum">
          <activiti:value id="true" name="Yes"/>
          <activiti:value id="false" name="No"/>
        </activiti:formProperty>
        <activiti:formProperty id="explanation" name="Explanation"/>
      </extensionElements>
    </userTask>
    <sequenceFlow sourceRef="evaluateLoanRequest" targetRef="approvalGateway" />
    <boundaryEvent id="escalationTimer" cancelActivity="true" attachedToRef="evaluateLoanRequest">
      <timerEventDefinition>
        <timeDuration>PT1M</timeDuration>
      </timerEventDefinition>
    </boundaryEvent>
    <sequenceFlow sourceRef="escalationTimer" targetRef="evaluateRequestByManager" />
    <userTask id="evaluateRequestByManager" name="Evaluate loan request by manager" activiti:candidateGroups="management">
      <extensionElements>
        <activiti:formProperty id="customerName" name="Customer name" expression="${loanApplication.customerName}" writable="false"/>
        <activiti:formProperty id="income" name="Income of customer" expression="${loanApplication.income}" writable="false"/>
        <activiti:formProperty id="requestedAmount" name="Requested loan amount" expression="${loanApplication.requestedAmount}" writable="false"/>
        <activiti:formProperty id="creditCheckOk" name="Outcome of credit check" expression="${loanApplication.creditCheckOk}" writable="false"/>
        <activiti:formProperty id="requestApproved" name="Do you approve the request?" required="true" type="enum">
          <activiti:value id="true" name="Yes"/>
          <activiti:value id="false" name="No"/>
        </activiti:formProperty>
        <activiti:formProperty id="explanation" name="Explanation"/>
      </extensionElements>
    </userTask>
    <sequenceFlow sourceRef="evaluateRequestByManager" targetRef="approvalGateway" />
    <exclusiveGateway id="approvalGateway" />
    <sequenceFlow sourceRef="approvalGateway" targetRef="informCustomer">
      <conditionExpression xsi:type="tFormalExpression">${requestApproved == false}</conditionExpression>
    </sequenceFlow>
    <sequenceFlow sourceRef="approvalGateway" targetRef="processRequest">
        <conditionExpression xsi:type="tFormalExpression">${requestApproved == true}</conditionExpression>
    </sequenceFlow>
    <serviceTask id="informCustomer" activiti:type="mail">
      <extensionElements>
        <activiti:field name="to" expression="${loanApplication.emailAddress}" />
        <activiti:field name="subject" stringValue="Loan Request Denied" />
        <activiti:field name="html">
          <activiti:expression>
            <![CDATA[
              <html>
                <body>
                  Hello ${loanApplication.customerName},<br/><br/>
                 
                  Your loan request has been denied for the following reason: ${explanation}.<br/><br/>
                 
                  Kind regards,<br/>
                 
                  The Loan Sharks Company.
                </body>
              </html>
            ]]>
          </activiti:expression>
        </activiti:field>     
      </extensionElements>
    </serviceTask>
    <sequenceFlow sourceRef="informCustomer" targetRef="theEnd" />
    <userTask id="processRequest" name="Process the loan request" activiti:assignee="fozzie" />
    <sequenceFlow sourceRef="processRequest" targetRef="theEnd" />
    <endEvent id="theEnd" />
  </process>


Any ideas?

thanks

-Sonam

Outcomes