Hello,
Very new to c Sharp and trying to query CRM 365 CE and I noticed that if a field comes back as blank or null it gives me this error?
In general how do you check for this and it's normal to have lots of nulls on any of the fields how does one handle that?
using (OrganizationServiceContext context = new OrganizationServiceContext(service))
{
// Pull contacts
var query = from account in context.CreateQuery("account")
join contact in context.CreateQuery("contact")
on account["primarycontactid"] equals contact["contactid"]
// where account["address1_city"] == "Woodland Hills" //&& account["name"] == "Peak Financial"
//where contact["fullname"] == "Dan Russ"
select new
{
Name = account["name"],
//Email = (contact["emailaddress1"] != null && contact["emailaddress1"] != ""),
// fax =! contact.Contains("fax"),
// fax = account["fax"],
CName = contact["fullname"],
CEmail = contact["emailaddress1"],
Manager = contact
};
foreach (var account in query)
{
//service.Update()
//Console.WriteLine(account.Name + " is run by: " + account.Manager["fullname"] + " Email " + account.Email + " fax " + account.fax);
Console.WriteLine(account.Name);
Console.WriteLine(account.CName + " " + account.CEmail);
}
Console.Read();
Hello,
Try to use GetAttributeValue<Type>("field name") to resolve your issue instead of ["field name"] like:
where account.GetAttributeValue<string>("address1_city") == "Woodland Hills"
instead of
where account["address1_city"] == "Woodland Hills"
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... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156