Hi
I check for an existing contact following form submissions to add a contact before adding a new contact.
The below snippet sort of works but I get regular errors as follows
"Condition for attribute 'contact.emailaddress1': null is not a valid value for an attribute. Use 'Null' or 'NotNull' conditions instead"
Can you tell me what to change?
var QEcontact = new QueryExpression("contact"); QEcontact.TopCount = 50; QEcontact.ColumnSet = new ColumnSet("emailaddress1", "contactid", "statecode"); QEcontact.Criteria.AddCondition("emailaddress1", ConditionOperator.Equal, Email); EntityCollection ec = service.RetrieveMultiple(QEcontact); if (ec.Entities != null && ec.Entities.Count > 0) { contactExists = 1; currentUser = ec.Entities[0].Id; sCurrentStatus = ""; foreach (var c in ec.Entities) { currentStatus = c.FormattedValues["statecode"]; sCurrentStatus = currentStatus.ToString(); } }
Or would this work better?
QueryExpression query = new QueryExpression { EntityName = "contact", ColumnSet = new ColumnSet("emailaddress1", "contactid", "statecode"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "emailaddress1", Operator = ConditionOperator.NotNull } } } }; EntityCollection ec = service.RetrieveMultiple(query); if (ec.Entities.Count > 0) //Check for EntityCollection count { foreach (var item in ec.Entities) { if (item.Attributes["emailaddress1"].ToString() == Email) { contactExists = 1; currentUser = ec.Entities[0].Id; currentStatus = c.FormattedValues["statecode"]; sCurrentStatus = currentStatus.ToString(); } } }
*This post is locked for comments