Allen4Tech
Allen4Tech

Reputation: 2184

How to get and set property object's property value in Activiti Script Task

I'm new to Activiti, I use a Script Task in my bpmn file and what to do some value conversion. Please check my code below.

pass variable when run the workflow:

Map<String,Object> var = new HashMap<String,Object>();
Person req = getRequest();
var.put("req", req);

runtimeService.startProcessInstanceByKey("demo",var);

getRequest method:

private static Person getRequest() {

    return new Person("John",30,"1");
}

my script task:

<scriptTask id="scripttask1" name="script task" scriptFormat="javascript">
  <script><![CDATA[
    	var req = execution.getVariable("req");
    	console.log(req);
  ]]></script>
</scriptTask>

The properties in Person are name, age and sex. I want to get the sex value in script task and then convert it to our format. I tried to write the code above in script task, but I don't know how to get the property from the object variable, anybody can help? Or anyway I can debug what I get in my script task? Thanks!

Upvotes: 1

Views: 838

Answers (1)

salaboy
salaboy

Reputation: 4133

I would recommend you not to use a script task and use a JavaDelegate with a ServiceTask if you are using Activiti 5 or 6. Script tasks end up being messy all the time. https://www.activiti.org/userguide/#bpmnJavaServiceTask

Upvotes: 1

Related Questions