cancel
Showing results for 
Search instead for 
Did you mean: 

defining global constants for a process

kethur
Champ in-the-making
Champ in-the-making
Hi,

I have about 20 constants values i want to define in my workflow definition which should be available to every process that will be created when we start the workflow.

If i define them as variables, it will create 20 rows in ACT_RU_VARIABLE and those variables are not cleared out until the process ends.  And our workflow runs for a long time.

I am looking for a solution something like, in the workflow bpmn.xml if we use activiti:field will it work as constant (Not storing in the database)?

Thanks,
Raj
7 REPLIES 7

trademak
Star Contributor
Star Contributor
Hi Raj,

if you use the field property it just gets injected in the service task class or listener class, not stored in the database.

Best regards,

kethur
Champ in-the-making
Champ in-the-making
Thanks.  But, how do i access that field value in the bpmn xml?  if i have a runtime variable i can straight away use it but fields are specific to java classes and I am not sure how to use them without setting them to runtime.

Could you please clarify? or refer to an example?

Thanks,
Raj

trademak
Star Contributor
Star Contributor
Hi,

I don't understand your question. Do you want to load the BPMN XML to read the field values?
Can't you create an abstract Java Delegate implementation that holds all the constant values?

Best regards,

kethur
Champ in-the-making
Champ in-the-making
Hi Thanks for your reply.

My requirement is that if we create activiti:field (s) in the XML I should be able to use them in the same XML just like runtime variables. 

The below example does not work (constant1Name == 'Constant 1 Value')  as i am trying to use the constant name in the highlighted area.  I would like a similar machanism.

<process id="workflow-constants-test" name="process1">
    <startEvent id="startevent1" name="Start">
      <extensionElements>
        <activiti:formProperty id="processVariableId1" name="processVariableName1" type="string" required="false"></activiti:formProperty>
        <activiti:formProperty id="processVariableId2" name="processVariableName2" type="string" required="false"></activiti:formProperty>
      </extensionElements>
    </startEvent>
    <userTask id="usertask" name="User Task With fields"></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <serviceTask id="servicetask1" name="Define Constants" activiti:class="com.unisys.holmes2.h2ng.workflow.business.impl.WorkflowConstantSetter">
      <extensionElements>
        <activiti:field name="constant1Name">
          <activiti:string>Constant 1 Value</activiti:string>
        </activiti:field>
        <activiti:field name="constant2Name">
          <activiti:string>Constant 2 Value</activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <sequenceFlow id="flow4" name="" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
    <sequenceFlow id="flow6" name="" sourceRef="usertask" targetRef="endevent1"></sequenceFlow>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <sequenceFlow id="flow7" name="" sourceRef="servicetask1" targetRef="exclusivegateway1"></sequenceFlow>
    <sequenceFlow id="flow8" name="" sourceRef="exclusivegateway1" targetRef="usertask">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${constant1Name == 'Constant 1 Value'}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow9" name="" sourceRef="exclusivegateway1" targetRef="endevent1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${constant1Name != 'Constant 1 Value'}]]></conditionExpression>
    </sequenceFlow>
  </process>

trademak
Star Contributor
Star Contributor
Okay, no you can't. That functionality is only available for process variables.

Best regards,

kethur
Champ in-the-making
Champ in-the-making
Thanks. 

Is there a way i can avoid filling ACT_RU_VARIABLE but, still use those constant values in the bpmn xml?

Thanks,
Raj

trademak
Star Contributor
Star Contributor
No, not using the default functionality.
What you could do is extend the ExpressionManager class and define your own ELResolver with the constant values.
Then you can use the values in expressions as well. But this would need some more investigation of the Activiti Engine on your side.

Best regards,