Groovy script to aggregate data in each iteration from POST request
Hi Team,
Can somebody please help me?
I've one data source - Groovy ( I wrote a script where it gives accounts numbers for each client) let's say got 3 account numbers, now I've to pass one by one as a POST request so that the response will give me some data (let's say points) next step I've is Data source loop.
Now the question is how can I store the points data for each client and aggregate them in each iteration?
Structure
DS - Fetch accounts
POST REQUEST and GET Points in response
Groovy Script - here I have to write the script (i tried to get the response from above request and tried to stored in list but it is storing the points of last record only)
DS LOOP
Thanks in advance!
If the datasink is inside the loop, then it should record each response. Without a screenshot, it's really difficult to properly help. You may have simply configured it wrong.
As for properties, the value will be overwritten on each iteration. Now, the properties are string name/value pairs. I'm assuming that you don't know how many iterations, so you could concatenate each value to the string and aggregate after the loop.
E.g.
Initial ""
Loop 1 : "20,"
Loop 2 : "20,23"
Loop 3 : "20,23,26"
etc.
Or have have two property values and total up on each iteration. E.g.
Initial : running-total = 0. count = 0.
Loop 1 : running-total = 20. count = 1.
Loop 2 : running-total = 43. count = 2.
Loop 2 : running-total = 69. count = 3.
Be aware, property values are strings. Before calculating them, you'll need to convert to integer and convert back to sting when saving them.