Skip to main content
Community site session details

Community site session details

Session Id : wyKnpJrG6CnV0PrvucJ7ZJ
Power Automate - Building Flows
Unanswered

Check if Record Exists in D365 and update, else create new record?

Like (0) ShareShare
ReportReport
Posted on 17 Aug 2020 10:07:02 by 4

Hi There!

I'm trying to create an MS flow that will link our cognito forms with our d365 crm. Specifically, I'm looking to do the following:

> A new entry is received to the specified cognito form

> An MS flow runs which searches to see if the company already exists on the CRM or not. If it does then it should update that record, if it does not then it should create an account record, contact record and a record in custom entity (Referrals)

The part bove is where I'm stuck. I can't work out how to tell it to check for duplicates.... does anyone have experience on this at all? I'm new to using this, so sorry if it's already been covered.

I've tried to say when a form is created, list all D365 Account records and put in a condition as the next step to look for any one of these items: contact name, phone, email, account or post-code, and if these are equal to anything supplied in the form, then just update that record, else create new, but it doesn't seem to work.

Any help would be awesome!

Thanks!

  • Jcook Profile Picture
    7,779 Most Valuable Professional on 18 Aug 2020 at 16:47:29
    Re: Check if Record Exists in D365 and update, else create new record?

    Hi @GHCRM2020 

     

    Try this expression:

    length(body('Filter_array'))
  • Mira Ghaly Profile Picture
    11,409 Moderator on 18 Aug 2020 at 10:54:48
    Re: Check if Record Exists in D365 and update, else create new record?

    @GHCRM2020 

    The error suggests that the list is empty ; your filter array is empty.

    Can you tell me what is the issue you are facing with the List Records?

  • GHCRM2020 Profile Picture
    4 on 18 Aug 2020 at 07:31:36
    Re: Check if Record Exists in D365 and update, else create new record?

    Hello @Mira_Ghaly and @Jcook,

     

    So, my condition looks like this: 

    length(outputs('Filter_array')?['body/value']) I have added in a filter array as the query under List Records would not work.
     
    The If Yes side looks as below: 
     
    Apply to Each> Value from List Records > Create a New Record in Custom Entity and set Organisation to the Account From List Records. This part fails and it seems to suggest the issue is with the condition: Unable to process template language expressions for action 'Condition' at line '1' and column '26182': 'The template language function 'length' expects its parameter to be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#length for usage details.'.
     
    GH CRM 2020.JPG
     
     
  • Mira Ghaly Profile Picture
    11,409 Moderator on 18 Aug 2020 at 01:16:32
    Re: Check if Record Exists in D365 and update, else create new record?

    @GHCRM2020 

    Can you share your flow History for the failed part?

  • Jcook Profile Picture
    7,779 Most Valuable Professional on 17 Aug 2020 at 22:31:48
    Re: Check if Record Exists in D365 and update, else create new record?

    Hello @GHCRM2020 

     

    What is your length() expression look like?

     

    Also what error are you receiving?

  • GHCRM2020 Profile Picture
    4 on 17 Aug 2020 at 15:22:58
    Re: Check if Record Exists in D365 and update, else create new record?

    Hi @Mira_Ghaly ,

     

    Thanks, this is helpful.

     

    Just a question though, this pulls in the data i need, but for the condition I need this:

    If yes - create a record in the custom entity relating to this account record; If no, create the new account, contact and custom entity records. 

     

    So underneath the condition in the Yes/No columns, I've added the CDS > Create New Record but fro the Yes option, it is failing and looks as though it is trying to apply this to ALL records, not just the one I need... am i missing something? Screenshot below for info.FLOW1.JPG

    Thanks!

  • Mira Ghaly Profile Picture
    11,409 Moderator on 17 Aug 2020 at 10:34:31
    Re: Check if Record Exists in D365 and update, else create new record?

    @GHCRM2020 

    You need to use List Records with a filter expression depending on the field that you want to match duplicate on , in the below example i am checking on fullname and you should replace '' with the value from the form that you want to match against.

    Mira_Ghaly_0-1597660232452.png

    Then you will add a condition expression to check if the List returned records then it has duplicates otherwise use the condition as below:

    with Left hand side equals:

    length(outputs('List_records')?['body/value']) is greater than 0 , Yes Do NOthing , No Create the records you are after.

    Mira_Ghaly_1-1597660365681.png

     

    If this post helps you with your problem, please mark your as Accepted solution.

    If you like my response, please give it a Thumbs Up.

    MG (Naturally Curious)

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Loading complete