I am trying to create an entity in CRM 2011 (not from view, but what in CRM 4 could be called DynamicEntity ... with my custom attributes). The code below gives me this error, and I'm not sure why. This exact code works if I remove the new_accounttype attribute and try to use a different custom attribute.
CRM seems to have decided that the OptionSetValue parameter is set as the value for this key value pair. new_accounttype is a select list (or OptionSet in CRM 2011), and the value 100000003 been pulled from the front end to be valid.
Error: A validation error has occurred. The value "new_accounttype" in the account type is out of range.
What am I doing wrong?
public static void CreateAccount(string accountName, string accountType) { //Create properties KeyValuePairOfstringanyType[] attributes = new KeyValuePairOfstringanyType[2]; attributes[0] = new KeyValuePairOfstringanyType() { key = "name", value = accountName ?? "" }; attributes[1] = new KeyValuePairOfstringanyType() { key = "new_accounttype", value = new OptionSetValue() { Value = 100000003 } }; ////Create DynamicEntity Entity accountToCreate = new Entity(); accountToCreate.LogicalName = "account"; accountToCreate.Attributes = attributes; try { service.Create(accountToCreate); } }
source share