Posts

Showing posts from 2017

Dynamics 365 sub-grid add new and add existing

Image
In Dynamics 365, if you put a sub-grid to display related records in a parent, there is always a plus (+) sign to allow user either adding a new child record or an existing record. The default behavior when user clicks the plus (+) sign is to display a lookup box, user can then click the lookup to drop down a list of child records or click the New button at the bottom of the drop down list. However, sometimes we may want to force the plus (+) sign to open the new record form straight away without displaying the lookup drop down to users. For example, we have a parent entity called Project, which is a custom entity. And we create a second custom entity called Service Contract, which has N to 1 relationship to Project. The project form looks like below. For the purpose of the demo, we say the requirement is to always open the new service contract form when user clicks the plus (+) sign. The easiest way to do this is to change the Project lookup field in the Service Con...

Dynamics 365 SDK Metadata Diagram Tool

I needed to document the as-built data model (entities, attributes and relationships) for customer's Dynamics 365 implementation and thought I should give the metadata diagram tool that comes with SDK a go ... The metadata diagram tool has been around quite sometime, it is located at: SDK\SampleCode\CS\Metadata\Diagram It seems like the solution hasn't been updated for quite sometime, and it is still trying to connect to the 2011 organization web service to get the organization service proxy object. And during my initial testing, it couldn't connect to Dynamics 365 instance (8.2). So I had to modify the code a bit to get it to work. Here is what you need to do: Open the solution in Visual Studio, I am using 2015. Restore the NuGet packages, and upgrade to the latest version of the packages. Also download and install the Microsoft.CrmSdk.XrmTooling.CoreAssembly NuGet package, the solution will eventually has the following packages installed. <packages>  ...

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...