I have built a flow that will create a Dynamics 365 task when I copy an email (the "Target Email") to a specific folder in Outlook 365. The flow is working so far, but I am trying to make 2 enhancements and am not sure how to get them done. The current, working flow is below.
I would like to check the D365 Contact entity for the presence of the Target Email's recipient, which could be in emailaddress1, emailaddress2 or emailaddress3. If the email address exists, I would like to set the task's Regarding field to the relevant Contact. I assume I need to grab the contactid of the relevant Contact to facilitate this, but I don't know how to accomplish that. Once I have the contactid, is it as simple as inserting that variable into the task's Regarding field, or is there more to it?
There is one more complication that I can't figure out. The Target Email may have multiple recipients. How do I isolate each email address so that I can create a separate task for each, and check each one against the Contact database per the paragraph above?
Thanks for the help!
Solved! Go to Solution.
To get the contact details you need to filter by email address 1, 2, and 3.
Here I am assuming email address will be unique in your contact lists.
The expression I used to find the count is as follows
The expression I used for the above compose 2 is as follows:
Thanks so much for the guidance @abm! I have tried implementing your solution but am doing something wrong. I am getting the following error: "The inputs of workflow run action 'Compose' of type 'Compose' are not valid. The variable 'EmailAddresses' must be initialized before it can be used inside action 'Compose'."
I added your 'split' subroutine first, then added the 'filter' subroutine. See steps below. I played around with the variable EmailAddress a bit but it didn't fix anything. I tried initializing it as "email@example.com;firstname.lastname@example.org@;email@example.com" and as the output of "Grab Recipients", and also tried Set Variable for EmailAddress to Grab Recipients.
Here is the state of that section of the flow:
Thanks for your reply. Looks like your Set Variable mapping to an output of some other compose. Is this need to change to the previous step which is intialise variable.
I'm not following that. Sounds like you're saying that I need to make the Value of the Set Variable step equal to Initialize Variable step? When I try that, I get this error: "The inputs of workflow run action 'Set_variable' of type 'SetVariable' are not valid. Self reference is not supported when updating the value of variable 'EmailAddress'."
Also, I should note that I didn't see a Set Variable step in your initial post. I added it while I was troubleshooting (although it didn't fix anything).
I took screenshots of the current flow, and of the results of a test run. Here is the current flow:
And here are the results of the run test:
Thanks for the screenshot. Could you please tell me after the initialize variable you are setting variable name value to some other output? You already initialised with certain values and replaced immediately after the next step? Which ever output you are mapping is not having a comma separated values hence its not returning as array for the split and getting the flow error.
... Could you please tell me after the initialize variable you are setting variable name value to some other output? ...
That is set to the output of the "Grab Recipients" step. You didn't have a Set Variable step in your suggestion, and I wasn't sure if one was necessary after an Initialize Variable step. So when the flow wasn't working, I added the Set Variable step to see if it solved the problem (which it didn't).
Do I need to Set a variable after I initialize it, or should I just delete it? If not, is the string in the Initialize Variable step correct? I have "firstname.lastname@example.org;email@example.com@;firstname.lastname@example.org", which I copied from your example. The 'at' signs look oddly placed, and I don't know if this will work when I have a recipient with a domain that isn't dotcom.
You can delete this step and directly map the values under the initialise. Yes that was a typo from my side. You need to make sure Grab Recipients returns with similar format where you can split the values after using the semi-colon. If you need a screen share and fix please send me the details by email.
Making progress! I have cleaned it up, but the test is still failing at the 'split' formula. I get this error:
"ExpressionEvaluationFailed. The execution of template action 'Apply_to_each_email_address' failed: the result of the evaluation of 'foreach' expression '@outputs('Split_EmailAddress')' is of type 'String'. The result must be a valid array."
But when I change that to array, I get the following error at the step that initializes the email address variable:
"BadRequest. The variable 'EmailRecipients' of type 'Array' cannot be initialized or updated with value 'email@example.com' of type 'String'. The variable 'EmailRecipients' only supports values of types 'Array'."
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!
Check out the community blog page where you can find valuable learning material from community and product team members!