09-29-2023 09:36 AM - edited 09-29-2023 09:38 AM
is there an easier way to do this?
I have 3 companies with 5 warehouses each
so I do 3 searches t find all the costs in each warehouses and then just add the data pills together and this worked fine.
but then I started seeing the Nil can't be coerced error so some warehouses will be blank.
do I need to loop through each search and do a if .present to add them together? or is there a trick I'm missing like in SFDC where there is a way to treat NULL as 0
also, is there a way to do a loop through 3 searches? or do I need to create a list variable which I'm trying to do but can't seem to combine the 3 searches into a single list
sorry if these are basic questions very new
Solved! Go to Solution.
09-29-2023 03:25 PM
There are a lot of ways to do this, but it depends on how your data is formatted. If you can make an array of all of the costs, you can use [array].compact.sum, where compact will eliminate the nil values. Otherwise, if you want to add them up individually, you will need to handle nil values with .present? like you mentioned. Something like:
([wh1].present? ? [wh1] : 0) + ([wh2].present? ? [wh2] : 0) ... and so on
For your second question, you can loop through three searches, but first you need an input to determine how many times to loop. Here's the general idea:
Hope this helps
09-29-2023 03:09 PM
I got it working but its NOT pretty so have 3 search actions 1 for each company pulling 5 Cost fields each.
Then I created I List variable and created 15 Update List variable actions to add those 15 fields to the list.
then I looped through the list variable checking for nil and adding to my original variable to ensure it was a float.
this is working but like I said not pretty I was hoping to pass the searches datapil directly into a variable list which i suspect can be done but I tried everything I could think of.
tonight, this will run in sandbox and I'm curious how long it will take to crunch 2500 or so parts
09-29-2023 03:26 PM
Glad you made some progress. If you can provide some examples of how the response is formatted, I'm sure there are more elegant and efficient ways to do this.
09-29-2023 03:25 PM
There are a lot of ways to do this, but it depends on how your data is formatted. If you can make an array of all of the costs, you can use [array].compact.sum, where compact will eliminate the nil values. Otherwise, if you want to add them up individually, you will need to handle nil values with .present? like you mentioned. Something like:
([wh1].present? ? [wh1] : 0) + ([wh2].present? ? [wh2] : 0) ... and so on
For your second question, you can loop through three searches, but first you need an input to determine how many times to loop. Here's the general idea:
Hope this helps
11-16-2023 09:48 AM
Gary,
Can you explain/give an example of step #3
"Use the repeat helper list in a repeat action to loop 3 times"
I have a repeat helper list, how do I iterate through it. or update the sequence?
Thanks