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
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);
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);
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)
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;
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,902 Super User 2024 Season 2
Martin Dráb 229,336 Most Valuable Professional
nmaenpaa 101,156