In Unified Service Desk, there is the concept of Entity Search. These allow you to query Dynamics 365 through FetchXml in order to retrieve data. You can use Entity Search in Windows Navigation Rules and in the DoSearch action of the CRM Global Manager. You can also call Entity Search through code.
Entity Search is useful to retrieve data that is not currently on the USD form, but exists in Dynamics 365. For example, let’s say you want to get the opportunities related to an account.
In the USD configuration page in Dynamics 365, click on Entity Searches:
You will see below. Click New:
We can create and download the FetchXML using Advanced Find that we will use in the entity search. Select an account as a placeholder that we will change shortly:
The FetchXML is below. We then replace the account with a replacement parameter from USD that holds the account, [[account.accountid]g]:
<fetch mapping="logical" output-format="xml-platform" version="1.0" distinct="false"> <entity name="opportunity"> <attribute name="name" /> <attribute name="customerid" /> <attribute name="estimatedvalue" /> <attribute name="statuscode" /> <attribute name="opportunityid" /> <attribute name="createdon" /> <order descending="true" attribute="createdon" /> <filter type="and"> <condition value="[[account.accountid]g]" attribute="parentaccountid" operator="eq" uitype="account" /> </filter> </entity> </fetch>
We can now create a new entity search. Click New and enter the data. We will call the entity search Opportunity Search:
Now let’s use the entity search.
DoSearch
DoSearch is an action that is part of the CRM Global Manager. If you were to create an action call and call the DoSearch action, you would see the parameters:
name | The name of the EntitySearch record to be used for searching. |
global | True if you want the search results tied to the global session to be cleared. Care should be taken when storing search results in the global session as these are not automatically freed by the system. Calling ClearEntityList is exceptionally important in this case. |
maxcount | The maximum number of records to store in the EntityList results from this call. |
In our example, we have an in place windows routing rule that displays an Account that is selected. The Account has the replacement parameter [[account.accountid]g]. We can run our DoSearch action from the USD debugger.
Select an Account. Then, open the debugger and select the CRM Global Manager hosted control, action = DoSearch, Data = Opportunity Search (the name of the entity search). Then refresh the data parameters. You will see Opportunity Search as a returned data set, with the fields from the FetchXml returned:
Instead of calling the action this way, we could add it to an action in USD. Create a new action:
We will attach this to the BrowserDocumentComplete event of the Account, so when an account is loaded, the opportunity search will run:
Now, when you run USD and select an account, you will see the Opportunity Search is run and the data is returned:
Run from Code
If you want to run an entity search from code, here is an example of running the same search from a hosted control. The search returns the fields selected in the FetchXML:
string searchName = "Opportunity Search"; var entityService = AifServiceContainer.Instance.GetService<IEntitySearchService>(); EntitySearchRequest entitySearchRequest = new EntitySearchRequest(searchName); entityService.GetEntitySearchResults(entitySearchRequest, (entitySearchResponse) => { foreach (Entity e in entitySearchResponse.Entities) { // Do something foreach (var attribute in e.Attributes) { MessageBox.Show(String.Format("Key: {0}, Value: {1}", attribute.Key, attribute.Value.ToString())); } } }); }
It will output the opportunity attributes selected:
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL
I have a scriptlet which get the incident ID and pastes it on the $Context. I then use this value on the replacement parameter but the search returns a zero results. And when I hardcode the guid it comes back with the results. Please help below is the code.
buy antibiotics without prescriptions http://gificlimited.com/shop/acheter-spedra-en-ligne.html broward regional health planning council