Compare Two Lists for matches. Extract key from matching index

So I’m currently working to collect Engine hours from Samsara, then find the corresponding Meter in my MaintainX system, and update the hours for each meter.

I have succeeded in pulling the meters as a list, filtering for Forklifts only. I have also pulled the engine seconds given by Samsara and scaled them to hours and stored the name and hour values in a list. The issue I’m having is trying to get my Flow to scan through the Meters list to find a match for the Samsara index’s name value, then when/if a match is found send the hours for said index match forward. When the match occurs I would also need the Meter ID which is inside the Meters list. I tried using an Eval and now an If block to no real avail. Any help is greatly appreciated.

Top Flow line is for Samsara, and bottom is for MaintainX, both end in Collect blocks with the appropriate lists.

Added note, the For Loop on the bottom section throws an error, but all the data collected is correct and valid. Ignore the error as it does not impact the end result I’m looking for.

MaintainX list structure:
image

Samsara list structure:
image

Hi @dbrass137

Welcome to the forums!

Once you have your two lists from the collect blocks, it will be easier to just perform the logic directly in an Evaluate Block from there.

I tried to recreate the shape of your data, so please try this solution:

Samsara.map((samsaraItem) => ({
  eh: samsaraItem.eh,
  id: MaintainX.find((maintainXItem) =>
    maintainXItem.asset.name.includes(samsaraItem.name)
  ).id
}));


It should give you the final list

@flows-daniel

First off, THANK YOU! I have been getting beaten by this all day and this solution worked! Only have one hang up now, for some reason the Samsara data of eH (the engine hours) is passed into everything in orange text and is treated as a number/int the whole time until I use the provided MaintainX API POST to send it in. I keep getting an error stating that it “must be a number”, and the fail output on that block shows it in green like a string. Do I need to define the value type in the body text or something?

Error I’m getting:

Previous block shows it as a number:

@dbrass137

Glad to hear the solution helped :slight_smile:

what does your request body look like right now before the variables are filled and what is shown in the console for this request?

If you’re wrapping the variable names in quotes in your body request it will be treated as a string.

Paris_Tuileries_Garden_Facepalm_statue

Okay, wow. So yes, I did have quotes around that variable in the body. Leftovers from before it was a variable. You are the best Thank you @flows-daniel

1 Like

Thank you for sharing this flow, there are lots of worthwhile observations for us for areas we can improve. I’m happy Daniel helped you resolve the issues. Please continue to share you feedback with us, we’re listening and taking notes on how to make things easier.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.