Implementing Internal Calculations in CAMUNDA 8 Without External Code

I am currently using CAMUNDA 8 primarily as a rules engine. After the rules execution, new variables are generated, and I am looking to perform calculations with these variables and store the result into new variables. While I am aware that these calculations can be executed through service tasks with the logic implemented in external code. I would like to know if there is any recommended approach within CAMUNDA 8 that facilitates this kind of internal calculation logic implementation?

Hi,

You can get a long way just using Feel expressions in a script task…

I have a nett preset value financial calculation built this way currently in production…

Regards

Rob

Hi @Webcyberrob
Thank you for your response. In my scenario, I need to perform calculations that will result in four distinct values (not sure exactly how many but more than one) and each of which should be stored in new variable within the process. My question is is it feasible to do these calculations and assigning to variables within a single script task? or is it necessary to use multiple script tasks, one for each variable assignment?
If you have any examples or templates of similar implementation, that would be helpful.

Hi,

One technique you can use is to return a ‘compound’ Json structure as a process variable using a FEEL script task.

Se example below which basically takes a date as input and determines the last business day of the current month (EOM) and the business day closest to (just after) the 15th of the month (MOM). These two attributes (and others) are returned in a json struct as a process variable we refer to as campaignDates

{
EOM : last day of month(date(runDate)),
EOM_DOW : day of week(date(EOM)),
EOM_REDRAW : if (EOM_DOW = “Sunday”) then (date(EOM) - duration(“P2D”))
else
if (EOM_DOW = “Monday”) then (date(EOM) - duration(“P0D”)) else
if (EOM_DOW = “Tuesday”) then (date(EOM) - duration(“P0D”)) else
if (EOM_DOW = “Wednesday”) then (date(EOM) - duration(“P0D”)) else
if (EOM_DOW = “Thursday”) then (date(EOM) - duration(“P0D”)) else
if (EOM_DOW = “Friday”) then (date(EOM) - duration(“P0D”)) else
if (EOM_DOW = “Saturday”) then (date(EOM) - duration(“P1D”)) else
date(EOM),
MOM : string(date(runDate).year) + “-” + (if (date(runDate).month) < 10 then “0” else “”) + string(date(runDate).month) + “-15”,
MOM_DOW : day of week(date(MOM)),
MOM_REDRAW : if (MOM_DOW = “Sunday”) then (date(MOM) + duration(“P1D”)) else
if (MOM_DOW = “Monday”) then (date(MOM) + duration(“P0D”)) else
if (MOM_DOW = “Tuesday”) then (date(MOM) + duration(“P0D”)) else
if (MOM_DOW = “Wednesday”) then (date(MOM) + duration(“P0D”)) else
if (MOM_DOW = “Thursday”) then (date(MOM) + duration(“P0D”)) else
if (MOM_DOW = “Friday”) then (date(MOM) + duration(“P0D”)) else
if (MOM_DOW = “Saturday”) then (date(MOM) + duration(“P2D”)) else
date(MOM)
}

Hopefully you can see you can effectively have a different mini script per attribute, and combine these attributes into a single, composite process variable…

regards

Rob

Thankyou @Webcyberrob, Following your advice, I’ve successfully implemented the necessary calculation in single service task.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.