I am trying to create a new record in Dynamics CRM using C#.
Below is the code that I am using:
Entity Record = new Entity("new_edRecord");
Record["new_year"] = "2100";
Record["new_school"] = new EntityReference("new_school",new Guid("8ba53949-3947-e445-876c-001dd8b71c19"));
Record["new_gradelevel"] = "100000018";
organizationProxy.Create(Record);
When I execute this, I get the below error:
Unexpected exception from plug-in (Execute): Department.EdRecord.RecordCreate: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
I double checked to see if a school exist with the GUID by visiting the below url:
https://crm.site.com/orgname/api/data/v8.0/new_schools(8ba53949-3947-e445-876c-001dd8b71c19)
and this brought a result. Not sure what I am missing here.
It is a common convention to name CRM lookup fields as the entity name with
idappended.Is it possible that
Record["new_school"]should beRecord["new_schoolid"]?OR:
Perhaps the value
100000018does not exist in theRecord["new_gradelevel"]optionset. Maybe comment out that line and see what happens.