I'm somewhat of a beginner in Power Automate, but I haven't been able to find a solution for my specific use case. Any help would be greatly appreciated!
I have a Power Automate flow that queries our CRM's API to retrieve a list of companies using an HTTP GET request. I can only get 100 results per call, so I have to paginate it. I use an Apply to Each with an Append to array variable action to append the following information to my CompanyDetails variable from the Parse JSON that looks at that HTTP GET action:
"Name": "@{items('Apply_to_each_-_Companies')?['entity']['name']}",
"MainDomain": "@{items('Apply_to_each_-_Companies')?['entity']['domain']}",
"Domains": "@{items('Apply_to_each_-_Companies')?['entity']['domains']}",
"CompanyID": "@{items('Apply_to_each_-_Companies')?['id']}",
"StageID": "@{items('Apply_to_each_-_Companies')?['entity']['fields'][0]['value']['data']['dropdownOptionId']}"
The purpose of this flow is to then conditionally save email attachments to SharePoint utilizing information from the above array variable. The problem I'm encountering is that later in the flow, I have quite a few conditions that it needs to check against; specifically, I need to check whether the SenderDomain (a string variable I set from an email with an attachment) exists within the Domains in the array variable, and then retrieve just the object where it matches. "Domains" is an array of strings that usually contains one string, but sometimes contains 2 or more strings.
In my working version of this flow, I achieved this with an apply to each that loops through the CompanyDetails array variable and a condition that checks whether the domain matches. However, since there's 3,000 companies (and growing) on the list, this tends to take a very long time and makes the flow run for hours.
Unfortunately, I can't just make an array variable of all domains in the list, as I will need to reference the StageID and MainDomain from the specific company object later in the flow for conditions. So for example, this would be an output for one object in the CompanyDetails array variable out of 3,000:
"Name": "Company",
"MainDomain": "company.com",
"Domains": "["company.com","company1.org"]",
"CompanyID": "123456789",
"StageID": "1111111"
Now imagine my SenderDomain variable was also "company1.org".
Is there a way to check the entire CompanyDetails array variable for the one that matches the SenderDomain variable and fetch the just that company entry without an apply to each loop that iterates over each company in the array variable?