Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

SDK D365 Contact Creation

Posted on by

Hello,

I have had issue with the SDK in setting certain attributes for the contact entity using C#.

I am able to connect to the CRM and create contacts no problem with the Microsoft.Xrm.Tooling.Connector. 

However when creating the contact certain attributes are not available to be set, where as others are. 

For example,

eg I can set :

Entity newContact= new Entity("contact");

newContact["emailaddress1"] = 'test@test.com'

newContact["vin_salutation"] = new OptionSetValue(10000000)

and save the entity

However if I set some of the other entities

eg.

newContact["vin_primarylanguage"] = new OptionSetValue(200000000)

It will error when saving to the crm and I notice that when debugging that 'vin_primarylanguage' isn't in the list of attributes.

Strangely when editing the contact in the D365 interface I can set the value of this field and if I then edit the contact programatically using the Microsoft.Xrm.Tooling.Connector I can now edit and save the attribute.

It seems that when the SDK is initially creating a contact entity it does not map all the attributes. I have looked in D365 and I can't see a reason why certain attributes are not mapped when others are.

I could provide more details with the code but was wondering if anybody had similar issues or could point me in the right direction of what the issue may be?

Thank you

*This post is locked for comments

  • RE: SDK D365 Contact Creation

    Hi Goutam,

    Thanks for your suggestion, I did look into your suggestion and the value I am trying to set is in the Optionset, however the issue is more with the actual attribute 'vin_primarylanguage' strangely not  being visible in the attributes I can set with the SDK.

    Fortunately I have been able to get around the problem by using the Web API to set the value rather than the SDK.

    eg.

    JObject updateContact = new JObject();

    updateContact.Add("vin_primarylanguage", primaryLanguage);

    // Update the contact the Primary language

    HttpResponseMessage updateResponse = await httpClient.SendAsJsonAsync(new HttpMethod("PATCH"), "api/data/v8.2/contacts(" + contactId + ")", updateContact);

  • RE: SDK D365 Contact Creation

    Hi Adrian,

    Thanks for your suggestion, however I had already tried this without success.

    Fortunately I have been able to get around the problem by using the Web API to set the value rather than the SDK.

    eg.

    JObject updateContact = new JObject();

    updateContact.Add("vin_primarylanguage", primaryLanguage);

    // Update the contact the Primary language

    HttpResponseMessage updateResponse = await httpClient.SendAsJsonAsync(new HttpMethod("PATCH"), "api/data/v8.2/contacts(" + contactId + ")", updateContact);

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: SDK D365 Contact Creation

    Hello Michael,

    I don't think the issue is related to mapping or something else. As you are using late bound your code  will always validate at the time of execute create request.

    Below line is correct , the only thing you need to make sure the value which you provided might be missing in the optionset. Go to setting -> Customizations--> Customize the System --> Expand Entity --> Fields -> Find the field "vin_primarylanguage" ,  open the fields and check any option set items associated with similar value.

    newContact["vin_primarylanguage"] = new OptionSetValue(200000000)

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: SDK D365 Contact Creation

    Hi MichaelMartinAus,

    Try setting the field like this, and double checking that the option set value of 200000000 exists in your CRM instance.

    var optionSet = new OptionSetValue(200000000);
    newContact["vin_primarylanguage"] = optionSet;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,902 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,336 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans