Tuesday, March 7, 2017

Dynamics CRM 2016: Updating Lookup field value using CRM REST API

This article aims to guide you about the things to consider when making a REST API call to insert/ update a value in the lookup field in CRM.

Consider your CRM instance is having following two entities:

1) account >> This entity comes default with CRM instance
2) new_customer >> Custom entity having various fields, but we are typically interested in "new_account" which is a lookup to the account entity.



    public class Account
    {
        public string name { get; set; }

        public Guid accountid { get; set; }

    }

using Newtonsoft.Json;
public class Customer
    {
        [JsonProperty(PropertyName = "new_accountid@odata.bind")]
        public string new_accountid { get; set; }        

        public string new_customerRefNo { get; set; }        
    }

Notice, the JsonProperty in Customer class. This property needs to be set for all lookup fields in case if they are intended to be updated/ inserted using REST API. Name of this property should be set to - "[lookupfieldname]@odata.bind". In above case, [lookupfieldname] is "new_accountid"

Now you can populate values in Customer instance, and can send them in your REST API calls which will update lookup fields during PUT/ POST calls.

1 comment:

  1. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    Dot Net Training Institute in Chennai
    Software Testing Course in Chennai
    Core Java Training in Chennai
    PHP Certification in Chennai

    ReplyDelete

Thanks for visiting my blog.
However, if this helped you in any way, please take a moment to write a comment.

Thanks
Nirman