cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate I
Advocate I

Find Dynamics 365 contactid Associated With Specific Email Address

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!

 

Flow pt1 20200306.pngFlow pt2 20200306.pngFlow pt3 20200306.pngFlow pt4 20200306.png

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III
Super User III

Re: Find Dynamics 365 contactid Associated With Specific Email Address

Hi @GurBAL 

 

After initialise mapping add a compose and do a split against the initialise variable.

 

Can we do a screen share please? That will be much easier.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials

View solution in original post

13 REPLIES 13
Highlighted
Super User III
Super User III

Re: Find Dynamics 365 contactid Associated With Specific Email Address

Hi @GurBAL 

 

To get the contact details you need to filter by email address 1, 2, and 3.

 

See below

 

image.png

 

Here I am assuming email address will be unique in your contact lists.

 

The expression I used to find the count is as follows

length(body('List_records_2')?['value'])
 
This IF condition determines whether the record exists or not. Then under the yes condition you can add the rest of the logic to get the contact id. Because you are using list items flow will construct a loop once you map the contact unique identifier even if there is only one record.
 
The other question is asked is about how to split the email address.
 
You can use the split expression to get each email address.
 
Please see below example
 
image.png

 

The expression I used for the above compose 2 is as follows:

split(variables('EmailAddresses'),';')
 
Try using the above flow action methods and let me know how it goes.
 
Thanks


Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Highlighted
Advocate I
Advocate I

Re: Find Dynamics 365 contactid Associated With Specific Email Address

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 "a@a.com;b@b.com@;c@c.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:

Flow pt1 20200309.png

Highlighted
Super User III
Super User III

Re: Find Dynamics 365 contactid Associated With Specific Email Address

Hi @GurBAL 

 

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.



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Highlighted
Advocate I
Advocate I

Re: Find Dynamics 365 contactid Associated With Specific Email Address

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).

Highlighted
Super User III
Super User III

Re: Find Dynamics 365 contactid Associated With Specific Email Address

Hi @GurBAL 

 

Could you post a screen shot of your full flow and run time history where which step is failing?



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Highlighted
Advocate I
Advocate I

Re: Find Dynamics 365 contactid Associated With Specific Email Address

I took screenshots of the current flow, and of the results of a test run.  Here is the current flow:

Flow full1 20200309.pngFlow full2 20200309.pngFlow full3 20200309.pngFlow full4 20200309.pngFlow full5 20200309.pngFlow full6 20200309.png

 

And here are the results of the run test:

Flow testA-1 20200309.pngFlow testA-2 20200309.pngFlow testA-3 20200309.pngFlow testA-4 20200309.pngFlow testA-5 20200309.png

Highlighted
Super User III
Super User III

Re: Find Dynamics 365 contactid Associated With Specific Email Address

Hi @GurBAL 

 

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.

 

image.png



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Highlighted
Advocate I
Advocate I

Re: Find Dynamics 365 contactid Associated With Specific Email Address


@abm wrote:

Hi @GurBAL 

 

... 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 "a@a.com;b@b.com@;c@c.com", 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.

 

Thanks!

Highlighted
Super User III
Super User III

Re: Find Dynamics 365 contactid Associated With Specific Email Address

Hi @GurBAL 

 

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.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Highlighted
Advocate I
Advocate I

Re: Find Dynamics 365 contactid Associated With Specific Email Address

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 'recipient@contoso.com' of type 'String'. The variable 'EmailRecipients' only supports values of types 'Array'."

Highlighted
Super User III
Super User III

Re: Find Dynamics 365 contactid Associated With Specific Email Address

Hi @GurBAL 

 

After initialise mapping add a compose and do a split against the initialise variable.

 

Can we do a screen share please? That will be much easier.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials

View solution in original post

Highlighted
Advocate I
Advocate I

Re: Find Dynamics 365 contactid Associated With Specific Email Address

PMing you screenshare details now...

Highlighted
Super User III
Super User III

Re: Find Dynamics 365 contactid Associated With Specific Email Address

Hi @GurBAL 

 

Thanks for the screen share. Hope it was useful. If you have any more questions please post it. It's an awesome community.😀



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (5,994)