Posts

Showing posts from June, 2017

Dynamics 365 Web API get entity using alternate key value that has apostrophe/single quote in it

In Dynamics 365, you can create alternate key for an entity using one of the attributes. Entity can be retrieved using alternate key via Web API. This MSDN article gives you an example on how to do that:  https://msdn.microsoft.com/en-us/library/mt607871.aspx#BKMK_UsingAltKeys I had an interesting error today when performing a query using alternate key. I tried to get an entity record from the User entity (systemusers) using an alternate key that is configured in the User entity. The alternate key uses the internalemailaddress attribute, which contains users' email addresses. A user's email address is firstname.O'lastname@domain.com, and as you can see, there is an apostrophe/single quote in the email address. When performing the query via Web API to get the user record, you can construct the below Url and simply paste into the browse to see the JSON response. In this case, the Url is: https://organization.crm6.dynamics.com/api/data/v8.2/systemusers(internalemailadd...

Calling Web API with FetchXML in JavaScript

This functionality has been available in Dynamics 365 Web API for sometime, and here is the Microsoft article on some examples:  https://msdn.microsoft.com/en-nz/library/mt607533.aspx However, there was a bug previously exist in Web API that has been recently corrected and the fix has been released to Dynamics 365 Online around the 1st June 2017. The previous bug was that when the Web API receives the FetchXML request, it decodes the featchXML parameter twice. And as a workaround, we will need to perform encoding twice before the request is sent, like below. var fetchXml =  encodeURIComponent('your fetchXml goes in here') ; var req = new XMLHttpRequest(); req.open("GET", _webApiPath() +  encodeURIComponent ("accounts?fetchXml=" + fetchXml), true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("O...