Tuesday, 26 April 2016

CRM 2015 oData Vs CRM 2016 Web API – Part 3 – oData Metadata

When another version of CRM gets out, we all have to learn from 0 few things, and regardless the experience we all have, nobody can deny that sometimes it is frustrating when we experience an error/exception for the first time and more time we spend understanding the "why?" without finding the solution more we feel worst.

What i have found on the very start of the painful task of changing the Javascript code to meet the Web API requirements was that the way i was doing few things related to fields and entities just changed, as an example, the lookup field i wrote on my previous post.

To help me on that tedious task of updating or creating records trough the Web API i found my new best friend regarding that matter, the oData Metadata Service.

For who knows CRM, just go to the Settings - Customizations -  Developer Resources - Click to download the oData Metadata, i can tell you that will make your life just much easier when dealing with lookups now in CRM when using them in a custom web resource. In there, you will find the object model used by the Web API.

I have found how i could set a value on a lookup field from that file, the lookups are now the navigation properties, and because of that, sometimes, the Navigation Property name for that specific field is just different from what you used before, and in there you will be able to see what is the name you need to use.

Hope it helps.

Monday, 25 April 2016

CRM 2015 oData Vs CRM 2016 Web API - Part 2 - Setting a Lookup Field with NULL

 On the subject of CRM 2015 oData Vs CRM 2016 i will be posting the main differences that i have found when upgrading my client code to CRM 2016 Web API.

I could start with the methods (Create, Update, Retrieve,....), however, those things are easier to find in the SDK than this specific one.

Previously you could already use a method called Disassociate to set a lookup field to null, but that involves an additional call for each one of the fields to update. So, i can imagine that you would be doing something similar to:

var account = {};

account.primarycontactid = null;

XRM.Rest.Update(account, "accountSet", ...,...,...);

Don't mind with the (...) on the method call, in my case i have a generic class to expose the Odata Organization Functionalities, the point in here is how easy was to set the field to null.

Now with CRM 2016, because we have those lookups as Navigation Properties (please, see my previous post about Navigation Properties on CRM 2016 Web API), to be able to perform the same operation, we need to call the Disassociate method, in my case:

 Xrm.WebAPI.Disassociate(accountid, "accounts", "", "primarycontactid",
                        SuccessCallBack,
                        ErrorHandler, false);

Where the first parameter is the id of the account, the second is the type "accounts" and the forth one is the field to set up as null (remove the relation between those two entities.)

Hope it helps

Tuesday, 19 April 2016

CRM 2015 oData Vs CRM 2016 Web API - Part 1 - Entities Properties

 This is my first post on the subject CRM 2015 oData Vs CRM 2016 Web API.

I will start with for me something that took me some time to understand and use properly when upgrading from CRM 2015 to CRM 2016 on the client side

With the Web API, now we have two different types of fields (properties), the primitive properties and the lookup properties (navigation properties).

Primitive types

OData supports a wide range of data types but Microsoft Dynamics CRM doesn’t use all of them. The following table describes how CRM Organization service types are mapped to OData primitive types.

Navigation properties

In OData, navigation properties allow you to access data related to the current entity. When you retrieve an entity you can choose to expand navigation properties to include the related data. There are two types of navigation properties: single-valued and collection-valued.

The lookup properties as the name says, it represents a lookup (lookup, owner, partylist) in one entity to another, whereas primitive properties are the others (money, string, decimal, integer,status,...)

After a retrieve of an entity data, primitive properties can be used like (account.name), on the other hand, the navigation properties have to be used like 

 account["primarycontactid@odata.bind"] = "/contacts(" + primaricontactGuid + ")";

For more information please follow the MSDN link: 

https://msdn.microsoft.com/en-us/library/mt607990.aspx 

Hope it helps.


CRM 365 Cloud - Disassociate 2 records using typescript

In case you need to Disassociate 2 records, please find below the code that allows you to do that.      export async function DissociateE...