web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

SDK D365 Contact Creation

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    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;
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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)

  • MichaelMartinAus Profile Picture
    on at

    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);

  • MichaelMartinAus Profile Picture
    on at

    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);

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans