Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

CRM 2016 Real time integration - Build lookup in real time using REST API

Posted on by 805

Hello,

Is it possible to be done real time integration in particular field lookup to be populated with data from external application using REST API?

In other words, when the end user click on a lookup field, Dynamics CRM to make a call to a REST API and as a result the lookup to be populated with the data from the response.

Regards,

*This post is locked for comments

  • ist Profile Picture
    ist 805 on at
    RE: CRM 2016 Real time integration - Build lookup in real time using REST API

    Thank you very much Kokulan!

    It works fine.

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: CRM 2016 Real time integration - Build lookup in real time using REST API

    The task runner workflow will start when you create the schedule record and will wait until the Start time to execute the Sync and then update the time for next day and then wait until next execution time right.

    it's all good so far but what if you accidentally cancelled the workflow or the workflow failed for some reason.

    You do not want to create another schedule record do you?

    So what you can do is, make sure the Task Start time is correct and then manually trigger the workflow. For this, you have to set workflow as OnDemand

    Please see below

    ScreenClip-_5B00_192_5D00_.png

    Starting the workflow manually

    ScreenClip-_5B00_190_5D00_.png

    1780.ScreenClip-_5B00_191_5D00_.png

    ScreenClip-_5B00_192_5D00_.png

    This will now start the workflow. You can also see how your workflow executed, You can check if it's waiting. From Task record, go to background processes

    ScreenClip-_5B00_193_5D00_.png

    You should be able to see if the task started and waiting 

    5822.ScreenClip-_5B00_194_5D00_.png

    ScreenClip-_5B00_196_5D00_.png

  • ist Profile Picture
    ist 805 on at
    RE: CRM 2016 Real time integration - Build lookup in real time using REST API

    Hello Kokulan,

    I manage to understand what are you talking about (regarding the last two screenshots I am asking in my previous post).

    Only missing part is On Demand (Scheduled Task Runner trigger) you are mentioned above.

    Could you explain more about it?

    Regards,

  • ist Profile Picture
    ist 805 on at
    RE: CRM 2016 Real time integration - Build lookup in real time using REST API

    Hi Kokulan,

    I have a question regarding the following screenshots:

     6864.ScreenClip-_5B00_173_5D00_.png

    Are you using CWA That Syncs Data from External API in this example (or it is from the previous example for lookup population in real time)?

    Could you explain in more details the last two screen shots:

    5280.ScreenClip-_5B00_171_5D00_.png

    ScreenClip-_5B00_175_5D00_.png

    Where did you do the above scheduling?

    Regards,

  • Verified answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: CRM 2016 Real time integration - Build lookup in real time using REST API

    I thought the maximum number of records for the lookup is in 100s but if it's over 1K, the lookup loading time will be slower and if its 10s or over, it may not be very usable.

    You can accomplish this using many different approachs, I am going to mention that one that you do not have to pay more or do not have to do loads of maintenance and stuff

    01. You could create a Custom Workflow Activity (CWA)  - This will pull data from your external source and update the lookup entity records in CRM. Your external system must have a primary key and that is most likely be an integer based not a GUID based one. So what you can do you can add a field the lookup entity and make that as an alternate key.  Once you define this, when you update the records daily, you can check if the record already exists, and it does you don't have to create again and also do update if necessary.

    Alternate Key: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/define-alternate-keys-entity 

    02. Now that you have a CWA that syncs data from your external source to CRM lookup entity. Next step is how do you run this on a daily basis or hourly basis. You can create an entity lets call it Scheduled Task Runner.  You add DateTime field to this entity - let's call it Task Start Time.  You will then have to create a workflow that triggers on Record Create /On Demand of this Scheduled Task Runner Entity.  

    This workflow will have a waiting Condition to time out until the Task Start Time. It will also have a parallel waiting condition if you want to cancel the task. You can cancel the task by Deactivating the record in this example. This workflow is set to start on create and also on demand. If for some reason, if you cancelled the task. You can start again by manually running the workflow on the record.

    Please see the screenshots below

    ScreenClip-_5B00_175_5D00_.png

    ScreenClip-_5B00_174_5D00_.png

    The way the next running time is set, in this example, as shown below, set to run after a day but you can set to run any time you want.

    5280.ScreenClip-_5B00_171_5D00_.png

    You will trigger the task by creating a task runner record as shown below

    ScreenClip-_5B00_175_5D00_.png

    This will trigger workflow and it will wait until the set date and time, execute the sync and then update this date field with next running time and will start the waiting again.. and it will continue to run like this.  

    Let me know if you need any further info on this

  • ist Profile Picture
    ist 805 on at
    RE: CRM 2016 Real time integration - Build lookup in real time using REST API

    Hi Kokulan,

    Thanks for your help. Your solution works fine.

    It turned out that the size of the external data is quite large (~1000 records), which takes more than 10 seconds (lookup) to be presented to the user.

    It seems that the data should be created (and updated on daily basis) within the CRM entity physically.

    Could you give me some guidelines what is the best way? Custom workflow scheduled every night (for example)?

    Regards,

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: CRM 2016 Real time integration - Build lookup in real time using REST API

    Hi

    When we save the lookup values in an Entity in CRM, the DB integrity check checks if the lookup record exists in CRM.  Since we are setting up realtime integration and not saving the external data in CRM, we will have to remove the lookup field from the entity just beofre it saves and store the value in a non-lookup fields.

    Lets say the Lookup Value text was  : Web Api Lookukp value 1  and id was the GUID.  We could have two text fields on the entity where the external lookup is being used and store the Value and GUID as strings. This is what i meant by hydrating the lookup. So this will allow CRM to save successfully

    The next thing is, when the Record is Retrieved, you will have to get the values from these two text fields and set the lookup entity reference on Post Retrieve or Post Retrieve Multiple

    The solution will work on 2016 or older or even latest, all we are doing is taking advantage of  entity plugin messages

    Hope this helps

  • ist Profile Picture
    ist 805 on at
    RE: CRM 2016 Real time integration - Build lookup in real time using REST API

    Hi Kokulan,

    Thanks for your help.

    I have a question regarding your final instructions:

    "When you actually Save the record after selecting lookup, you will have to have a plugin to trigger on PreValidation and hydrate the lookup field into a text field and remove the Lookup attribute from attribute collection. And then on your post retrieve, you can just get the value from hydrated text field and populate the lookup field."

    What does "hydrated the lookup field into a text field" mean? Could you explain in more details the quoted text above?

    One more question: Does your solution work on CRM 2016?

    Thank you in advance and Regards,

  • Verified answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: CRM 2016 Real time integration - Build lookup in real time using REST API

    Hi Jaret

    Please try the following steps to get this working. You can increase the complexity of it depending on your requirements but here I just wanted to give you a simple example

    I first created two entities, one that's going to have the lookup field that lists external data that comes from Rest API and other is kind of a Virtual entity as it does not store any data

    ScreenClip-_5B00_201_5D00_.png

    The Test entity has a lookup to Web Api lookup entity

    ScreenClip-_5B00_194_5D00_.png

    Here is how it will look when you create a record on Test Entity

    ScreenClip-_5B00_195_5D00_.png

    ScreenClip-_5B00_198_5D00_.png

    I assume this is what you wanted to achieve? The data in the lookup does not exist in CRM but its displayed in CRM lookup and stuff

    ScreenClip-_5B00_199_5D00_.png

    The code to get the above working is as follows

    ScreenClip-_5B00_197_5D00_.png

    This gets you all the way up-to populating lookup and setting the value on the form.

    I wrote the query simple here but you can actually use the query that comes in the RetrieveMultiple request and return results accordingly if you want to go to the next level in terms of filtering.

    Even if you go to web api lookup Entity or query in advance find

    It will look like the data is in CRM

    ScreenClip-_5B00_202_5D00_.png

    ScreenClip-_5B00_201_5D00_.png

    But the data is actually in your external source and it is pulled via REST API

    When you actually Save the record after selecting lookup, you will have to have a plugin to trigger on PreValidation and hydrate the lookup field into a text field and remove the Lookup attribute from attribute collection.

    And then on your post retrieve, you can just get the value from hydrated text field and populate the lookup field.

    Hope this helps

  • ist Profile Picture
    ist 805 on at
    RE: CRM 2016 Real time integration - Build lookup in real time using REST API

    Thank you Goutam Das!

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans