How to get a specific value of data after submitting on first task



Just want to ask how to get a specific value of data after submitting on first task. After I click submit button and then the approver will click approve a sequential number depending on the company of the creator will be generated. I want to get the max number with the company if company is the same and have an existing number then +1 but if newly created processes without number then start with 1. But I cannot get the max number and the company of the processes as well. The task failed after I submit after approval. I do the generation on operations and set the number using groovy. See below code and custom query:

Groovy code
int numSeq = 0
if(pettyCashHeaderDAO.findByMaxPetCashNo().toString() == "")
numSeq = 1
def petCashNum = numSeq.toString().padLeft(6, '0')

return petCashNum

Custom Query

SELECT MAX(p.petCashNo)
FROM PettyCashHeader p
WHERE p.isApproved = true
ORDER BY p.preparedDate ASC

Please help. Thank you guys.


Submitted by Dibyajit.Roy on Mon, 02/20/2017 - 09:00

In my Process , I use the Custom query to retrieve the Max Req Id and then Increment it by 1 each time.
Here is the custom query

SELECT coalesce(Max(requestId), 0)
FROM RPrenewalProcess

note that the return type is count and all parameters are removed.

Now in my Task => operations
i use the Below script to increment the value.
(rPrenewalProcessDAO.MaxRequestId() + 1).toString();

note that in my case the variable to hold req id is of type text . If you have long variable , then no need to use toString();

Hope this helps

1 answer


Hi christianmichaelgarizala,

Unfortunely, the DAO obejct related to your object is not accessible from Groovy scripts, there is a knowm limitation that blocks us to use it. So you will never get your custom query executed and will always get a error !

I suggest you to do a connector before the task to get the desire information and in your groovy code for operation use it to increment and set to your object attribute.

Marcos Vinícius Pinto