Como usar CrmServiceClient para definir um valor de atributo nulo
Estou tendo problemas com o CrmServiceClient para atualizar os valores dos atributos para nulos.
Meu código está funcionando bem para valores não nulos, mas falha com uma exceção:
Referência de objeto não definida para uma instância de um objeto. em Microsoft.Xrm.Tooling.Connector.CrmServiceClient.AddValueToPropertyList (KeyValuePair2 Field, AttributeCollection PropertyList) at Microsoft.Xrm.Tooling.Connector.CrmServiceClient.UpdateEntity(String entityName, String keyFieldName, Guid id, Dictionary
2 fieldList, String applyToSolution, Boolean enabledDuplicateDetection, Guid batchId)
sempre que tento definir um valor nulo.
Até agora, tentei o seguinte:
// create Crm service client object
CrmServiceClient svc = new CrmServiceClient(
new System.Net.NetworkCredential("username", "password", "domain"),
"crmhost",
"443",
"crmorganization",
false,
true
);
// check the connection to CRM was successful
if (!svc.IsReady)
{
throw new Exception("Could not connect to CRM Organization.", svc.LastCrmException);
}
// create a Dictionary to store the attributes to be added to the entity
Dictionary<string, CrmDataTypeWrapper> attributes = new Dictionary<string, CrmDataTypeWrapper>();
//this doesn't work
attributes.Add("new_somedatefield", null);
// and this doesn't work
attributes.Add("new_somedatefield", new CrmDataTypeWrapper(null, CrmFieldType.CrmDateTime));
// this also doesn't work
DateTime? nullDate = new DateTime();
nullDate = null;
attributes.Add("new_somedatefield", new CrmDataTypeWrapper(nullDate, CrmFieldType.CrmDateTime));
svc.UpdateEntity("new_entityname", "new_entitynameid", (Guid)data[metaData.PrimaryIdAttribute], attributes));
Não há nada especificamente mencionado na documentação sobre a configuração de valores nulos.
Alguém conseguiu conseguir isso?
EDIT - Para esclarecer que preciso direcionar o Dynamics CRM 2015, o método Update no CrmServiceClient não estará disponível até 2016.