cancel
Showing results for 
Search instead for 
Did you mean: 

How can i check the expressions like normal java conditions

valarmathi
Champ in-the-making
Champ in-the-making
Hi,

I want to check the normal java conditions like a<b ,if condition is true send the mail to user otherwise end the task .
how can i do it .Please help me.

Thanks,
Valarmathi P
13 REPLIES 13

frederikherema1
Star Contributor
Star Contributor
Yes you can. You can use all comparison operators UEL supports (< > <= >= != ==)

valarmathi
Champ in-the-making
Champ in-the-making
<?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:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="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="process1" name="process1">
    <startEvent id="startevent1" name="Start"></startEvent>
    <serviceTask id="mailtask1" name="Confirmation Email" activiti:type="mail">
      <extensionElements>
        <activiti:field name="to" expression="xxxxx"></activiti:field>
        <activiti:field name="from" expression="xxxxx"></activiti:field>
        <activiti:field name="subject" expression="Confirmation mail"></activiti:field>
        <activiti:field name="html">
          <activiti:expression><![CDATA[Hi,

U got confirmation ,because ur salary is lessthan 10000.

Thanks,
Valarmathi P]]></activiti:expression>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <endEvent id="endevent2" name="End"></endEvent>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <userTask id="usertask1" name="Salary Comparision"></userTask>
    <serviceTask id="mailtask2" name="Rejected Mail" activiti:type="mail">
      <extensionElements>
        <activiti:field name="to" expression="xxxxx"></activiti:field>
        <activiti:field name="from" expression="xxxx"></activiti:field>
        <activiti:field name="subject" expression="Rejected mail"></activiti:field>
        <activiti:field name="html">
          <activiti:expression><![CDATA[Hi,

U not yet get confirmation ,because ur salary is greater than 10000.

Thanks,
Valarmathi P]]></activiti:expression>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <sequenceFlow id="flow3" name="" sourceRef="mailtask1" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow4" name="" sourceRef="usertask1" targetRef="exclusivegateway1"></sequenceFlow>
    <sequenceFlow id="flow5" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow6" name="${Salary&lt;10000}" sourceRef="exclusivegateway1" targetRef="mailtask1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${Salary<10000}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow7" name="${!salary&lt;10000}" sourceRef="exclusivegateway1" targetRef="mailtask2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!salary<10000}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow8" name="" sourceRef="mailtask2" targetRef="endevent2"></sequenceFlow>
  </process>
 
</definitions>

is this  correct,then i have write java class for normal java code is it.

Thanks,
Valarmathi P

frederikherema1
Star Contributor
Star Contributor
You can use the mail-task without any java-code.

valarmathi
Champ in-the-making
Champ in-the-making
How the mail will send the corresponding person,no need to fill the properties also for sending mail .

Thanks,
Valarmathi P

frederikherema1
Star Contributor
Star Contributor
Please read the user guide before asking random questions about stuff you encounter. We have done our very best of explaining everything in the user guide. Sending a mail is explained there…

valarmathi
Champ in-the-making
Champ in-the-making
Hi,

this is my process xml file

  <process id="provaJavaDelegate" name="delegateJar">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="inserimento dati libro1" activiti:candidateGroups="accountancy"></userTask>
    <userTask id="usertask2" name="verifica disponibilita libro1" activiti:candidateGroups="management"></userTask>
    <serviceTask id="servicetask1" name="javaCode" activiti:class="org.activiti.examples.bpmn.servicetask.BackwardsCompatibleExpressionDelegate">
      <extensionElements>
        <activiti:field name="text">
          <activiti:string>Hello World</activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
    <sequenceFlow id="flow3" name="" sourceRef="usertask2" targetRef="servicetask1"></sequenceFlow>
    <sequenceFlow id="flow4" name="" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
  </process>


i used this java class


public class BackwardsCompatibleExpressionDelegate implements JavaDelegate {

@Override
public void execute(DelegateExecution execution) throws Exception {
 
  String var = (String) execution.getVariable("text");
      var = var.toUpperCase();
      execution.setVariable("text", var);

  System.out
  .println(" I am in BackwardsCompatibleExpressionDelegate….");
 
}
}

its working fine means the process instance is created.
But i have one doubt, from the java class i have set the value for uppercase ,this value where can i get it while executing the process.
Please clear my doubt.

Thanks,
Valarmathi P

frederikherema1
Star Contributor
Star Contributor
Use the RepositoryService to get variables of a running process, so you can verify the values. If it's finished and history is on, use the HistoryService to get historicVariableUpdates (HistoricDetailQuery) for a finished process-instance

valarmathi
Champ in-the-making
Champ in-the-making
I used the RepositoryService class in the below method,i run the jUnit but i can't get the value.


public void startProcess() throws Exception {
  RepositoryService repositoryService = activitiRule.getRepositoryService();
  repositoryService.createDeployment().addInputStream("provaJavaDelegate.bpmn20.xml",
    new FileInputStream(filename)).deploy();
  RuntimeService runtimeService = activitiRule.getRuntimeService();
  Map<String, Object> variableMap = new HashMap<String, Object>();
  variableMap.put("name", "Activiti");
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("provaJavaDelegate", variableMap);
  assertNotNull(processInstance.getId());
  System.out.println("id " + processInstance.getId() + " "
    + processInstance.getProcessDefinitionId());
}
}

Thanks,
Valarmathi P

jbarrez
Star Contributor
Star Contributor
What exactly goes wrong? Which line doesn't work?