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
Thank you very much Kokulan!
It works fine.
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
Starting the workflow manually
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
You should be able to see if the task started and waiting
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,
Hi Kokulan,
I have a question regarding the following screenshots:
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:
Where did you do the above scheduling?
Regards,
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
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.
You will trigger the task by creating a task runner record as shown below
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
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,
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
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,
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
The Test entity has a lookup to Web Api lookup entity
Here is how it will look when you create a record on Test Entity
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
The code to get the above working is as follows
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
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
Thank you Goutam Das!
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156