Set enum value to process variable

cancel
Showing results for 
Search instead for 
Did you mean: 
ic2h
Active Member

Set enum value to process variable

Jump to solution

Hi!

We have to save process instance variable which is enum. For example: workflow has variable general_status which contains one of values:

public enum IwGeneralStatus
{
IN_WORK("InWork"),
WAITING_FOR_APPROVAL("WaitingForApproval"),
WAITING_FOR_PAYMENT("WaitingForPayment"),
PAID("Paid"),
COMPLETED("completed");
   
    // ...
}‍‍‍‍‍‍‍‍‍‍

We wanted to set one of this values via BPMN diagram when task being executed. So, we created a Service task which contains expression ${iwGeneralStatus.IN_WORK}‍  and tried to save it to our general_status:

but got next exception:

org.activiti.engine.ActivitiException: Unknown property used in expression: ${iwGeneralStatus.IN_WORK}‍‍‍‍

Is there a way to save enum to process variable via diagram?

1 Solution

Accepted Solutions
ic2h
Active Member

Re: Set enum value to process variable

Jump to solution

After long research I've found a way to put object value to process instance variable via Script task.

I used groovy scripting with following code:

import com.iw.rest.api.v1.groups.domain.IwGroup;

IwGroup initiatorGroup = new IwGroup("IW_INITIATOR");
IwGroup legalGroup = new IwGroup("IW_LEGAL");
IwGroup projectManagerGroup = new IwGroup("IW_PM");
IwGroup accountantGroup = new IwGroup("IW_ACCOUNTANT");

List<IwGroup> groups = [       
initiatorGroup,   
legalGroup,   
projectManagerGroup,   
accountantGroup
]

execution.setVariable("group_sequence", groups);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

Same thing could be used for enums:

execution.setVariable("general_status", com.iw.rest.api.v1.workflows.domain.IwGeneralStatus.IN_WORK);

Keep in mind that if you use groovy language in script task than you have to set script format field to groovy.

Otherwise it won't work.

View solution in original post

1 Reply
ic2h
Active Member

Re: Set enum value to process variable

Jump to solution

After long research I've found a way to put object value to process instance variable via Script task.

I used groovy scripting with following code:

import com.iw.rest.api.v1.groups.domain.IwGroup;

IwGroup initiatorGroup = new IwGroup("IW_INITIATOR");
IwGroup legalGroup = new IwGroup("IW_LEGAL");
IwGroup projectManagerGroup = new IwGroup("IW_PM");
IwGroup accountantGroup = new IwGroup("IW_ACCOUNTANT");

List<IwGroup> groups = [       
initiatorGroup,   
legalGroup,   
projectManagerGroup,   
accountantGroup
]

execution.setVariable("group_sequence", groups);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

Same thing could be used for enums:

execution.setVariable("general_status", com.iw.rest.api.v1.workflows.domain.IwGeneralStatus.IN_WORK);

Keep in mind that if you use groovy language in script task than you have to set script format field to groovy.

Otherwise it won't work.