top of page
  • Kyle Hill

Kylie Bot Part 7B - Useful Tools

During Part 7, we did a lot of work with asynchronous calls and it's often very difficult to test these because the calls to interfaces don't always return when you expect them to. Stephen Cleary helped me out here with the following blog. The result is that I have created a console application that you can use to test the async calls that we make to our CRMApi in the KylieBot project.

See the link to the project here.

Also, a couple of things to note during my experiments with the CRMApi project.

First, the xml we used in our CRMController class in the CRMApi project was generated using the Advanced Find functionality in Dynamics 365. The xml looks like this:

string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' returntotalrecordcount='true' > <entity name='contact'> <attribute name='contactid' /> <attribute name='fullname' /> <attribute name='emailaddress1' /> <filter type = 'and'> <condition attribute = 'emailaddress1' value = " + email + @" operator = 'eq' /> </filter> </entity> </fetch>";

The xml is generated as follows. Click on the Advanced Find icon in the top right of the screen (it looks like a funnel):

A screen like this should pop up:

Select the entity you want to search against (Contacts in our case) as show in the above. Next, specify the filters that we want to apply to the search. For our scenario, it will just be based on email address and I'll input some test data for illustrative purposes. The screen should now look like this:

Once this is done, you can click on the 'Download Fetch XML' menu button that will download the xml file to your local machine. If you open this file (in a web browser), you should see this:

We can use this directly in our class to retrieve a specific contact record(s) based on an email address. The only difference in our code is that we will dynamically specify the value field on the email address so that each time the method executes, it searches with the correct email address. The @ signs before the string just indicate the string will run over multiple lines so that it's easier to read in Visual Studio.

Some other gotchas to note. When doing the retrieve of a Dynamics 365 record, if the attribute doesn't contain any data, it will not be returned. Even if we specify the column in the retrieve request, the response will exclude it if doesn't contain any data. Be aware of this when executing the retrieves and handle the lack of a column by checking if it has been returned in the response.. We did this in the CreateCRMBotChat method of our Dynamics365Helper class in the CRMApi project by using the following line of code:


Just update the text between the double quotes to reflect the attribute you want to check for. Finally, if you are looking for attribute names and in particular, the primarykey of the entity, the best place to do it is in the fields view of the entity in the solution view we used in previous posts. Here you will observe all the fields and their names like this:

Remember to use the 'Name' field when referencing attributes in code.

Hope that was helpful and lookout for the next post on querying the Dynamics 365 Knowledge Base from Kylie Bot.

bottom of page