cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a simple service task?

wktham
Confirmed Champ
Confirmed Champ

Hi,

I am using trial version of APS v1.6.1.

I though want to try to create a service task that to do a simple calculation based on 2 input number from earlier user task. For example I have 2 number fields, A and B that user will need to input the numbers. In this service task, I just want to have result from A + B. Not too sure how to do this. Still goggling.

Thanks.

3 REPLIES 3

cjose
Elite Collaborator
Elite Collaborator

Hi Tham,

This post https://community.alfresco.com/community/bpm/blog/2016/11/15/activiti-enterprise-developer-series-se... will be a good start for you. More details about the usage of service tasks and script tasks can be found at APS Documentation  & Activiti User Guide: Script Task. For something as simple as a sum of two variables, script task/expression will be the easiest. Attached is a sample app, calculating the sum of two variables (var1 + var2) and displaying the output in a form (via a variable named 'var3').

Hope this helps.

Ciju

daisuke-yoshimo
Star Collaborator
Star Collaborator

If it is not necessary to explicitly indicate calculation process on the process diagram, you can use task listener(Expression).
Setting task listener on 'Apply' user task as following.

・Event
complete

・Type
・Expression
${task.setVariable("C", task.getVariable("A") + task.getVariable("B") )}

If it is necessary to explicitly indicate calculation process on the process diagram, you can use service task(Expression).

Setting service task as following.

・Task Type
Expression

・Expression
${execution.setVariable("C", execution.getVariable("A") + execution.getVariable("B") )}

gdharley
Elite Collaborator
Elite Collaborator

Just use a script task for somthign so trivial.

def var1 = execution.getVariable("variable1");

def var 2 = execution.getVariable("variable2");

def result = var1 + var2;

execution.setVariable("theResult", result);

Greg