- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2025 05:37 AM
Hi guys quick question. I do look up which returns (in this case) two records and for each item I set the flow variable to the total time (Duration) and I wish to add these flow variable iterations together to give a total sum. The flow variable result for each item in the look up is 10 and 42 respectively so I wish to return a total of 52. Can anyone advise on how I can do this please? I know it has to be simple, I just get solution it. Thank you so much
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2025 01:09 PM - edited ‎01-05-2025 01:17 PM
Hi @graeme1983 ,
If I understood correctly, at the end of each loop you want the total sum of each total duration. You may try below steps as mentioned sequentially to configure the flow and its actions. Hopefully it would work for you.
1. You can create two flow variables of Integer type, 'totalDuration' and 'totalSumDuration'.
2. Before 'Look up records' step you can set the 'totalSumDuration' flow variable to 0.
3. Then, inside 'For each item' step (within loop) first set the 'totalDuration' flow variable (this will hold 10 in first iteration and 42 in 2nd iteration).
4. Next, set the 'totalSumDuration' flow variable with script as below,
var sum = (fd_data.flow_var.totalSumDuration + fd_data.flow_var.totalDuration);
return sum;
Whatever value the 'totalSumDuration' flow variable holds, which is the total of all the durations, after all the iterations are complete, you can use that total value outside the for each loop as well as per your need.
If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.
You may mark this helpful as well if it helps you.
Thanks,
Animesh Das
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2025 01:09 PM - edited ‎01-05-2025 01:17 PM
Hi @graeme1983 ,
If I understood correctly, at the end of each loop you want the total sum of each total duration. You may try below steps as mentioned sequentially to configure the flow and its actions. Hopefully it would work for you.
1. You can create two flow variables of Integer type, 'totalDuration' and 'totalSumDuration'.
2. Before 'Look up records' step you can set the 'totalSumDuration' flow variable to 0.
3. Then, inside 'For each item' step (within loop) first set the 'totalDuration' flow variable (this will hold 10 in first iteration and 42 in 2nd iteration).
4. Next, set the 'totalSumDuration' flow variable with script as below,
var sum = (fd_data.flow_var.totalSumDuration + fd_data.flow_var.totalDuration);
return sum;
Whatever value the 'totalSumDuration' flow variable holds, which is the total of all the durations, after all the iterations are complete, you can use that total value outside the for each loop as well as per your need.
If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.
You may mark this helpful as well if it helps you.
Thanks,
Animesh Das
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 12:44 AM
Thank you so much sir. I banged my head off a wall for hours trying to figure it out. I really appreciate you taking the time to respond so thoroughly 🙂 Thanks again Animesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2025 06:58 PM
you can follow steps mentioned by Animesh
let us know if stuck somewhere
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader