I have an array where I have Ticket ID, Company Names and Time spent on a work order, however I need to be able to combine the Company1 Entries into one one object and add up the time by ticket id, or for any duplicated ticket id. so it looks like: {"TimeArray":[{"arTicket":2562,"arName":"Company1","arTime":0.9666666666666667},{"arTicket":2564,"arName":"Company2","arTime":0.08333333333333333},{"arTicket":2562,"arName":"Company1","arTime":0.4166666666666667}"]
So far I haven’t been able to figure out how to use a while loop or repeat to go back through the results and create a new array with the arTime entries added together for a ticket Id.
This will create a new array where the key is the ticket_id which you are repeating through. Inside each will be an array of the entries with that ticket id (which you can refer to with $value) which you can use the sum formatter on the times in a set value step
Set the output filter option of the repeat to ‘Exclude’
You could also have a set value step for arTicket and arName with values: $value[0].ticket_id and $value[0].name
which will take the ticket id and name from the first item in each grouped array
Can you share a screenshot of the new set value step for arTime?
It seems you can’t use a formatter inside the sum. You would possibly need a repeat inside to run through the tickets and calculate the time difference. Then you would use the sum after that repeat on its results.
An alternative, and probably easier method, would be to create a view in your DB that you would use instead of the table in your query:
something like this (you will need to adjust the table/column names accordingly - and also assuming MySQL)
SELECT *,
time_to_sec(timediff(end, start)) / 3600 AS ticket_hours
FROM tickets