c# - Retrieve "null values" from OrganizationServiceContext -
i having problem retrieving empty columns "null values" in crm 2011 using c# , organizationservicecontext.createquery
method. code below. problem subtype
. when null error: "object not set instance of object". can please assist?
public list<opportunities> getopportunitieslist() { using (_orgservice = new organizationservice(connection)) { organizationservicecontext context = new organizationservicecontext(_orgservice); // create linq query. datetime getdate = datetime.now.adddays(-3); var query = (from r in context.createquery<opportunity>() join c in context.createquery<contact>() on r.contactid.id equals c.contactid rc z in rc.defaultifempty() r.createdon > getdate && r.new_type.value != null orderby r.contactid select new opportunities { opporunity = r.new_opportunitynumber, //region =getaccountregionsbyid(a.new_region.value), accountid = r.customerid.id, topic = r.name, status = r.statecode.value.tostring(), pcustomer = r.customerid.name, estreve = (decimal)r.estimatedvalue.value, owner = r.ownerid.name, salesstagecode = r.salesstagecode.value, pipelinephase = r.stepname, opptype = getalloptionsetvalues(r.logicalname, "new_sf_recordtype", r.new_sf_recordtype.value), subtype = getalloptionsetvalues(r.logicalname, "new_type", r.new_type.value == null ? default(int) : r.new_type.value), estclosedate = r.estimatedclosedate.value, actualrev = (microsoft.xrm.sdk.money)r.actualvalue, probability = r.closeprobability.value, weighedrev = (decimal)r.new_weightedvalue.value, email = z.emailaddress1, createdon = r.createdon.value, modifiedby = r.modifiedby.name, modifiedon = r.modifiedon.value }).tolist(); foreach (opportunities o in query) { o.region = (from d in context.createquery<account>() d.accountid == o.accountid select getalloptionsetvalues(d.logicalname, "new_region", d.new_region.value)).firstordefault(); } return query; } }
i'm guessing r.new_type optionsetvalue. you'll need check null instead of value being null. try this:
public list<opportunities> getopportunitieslist() { using (_orgservice = new organizationservice(connection)) { organizationservicecontext context = new organizationservicecontext(_orgservice); // create linq query. datetime getdate = datetime.now.adddays(-3); var query = (from r in context.createquery<opportunity>() join c in context.createquery<contact>() on r.contactid.id equals c.contactid rc z in rc.defaultifempty() r.createdon > getdate && r.new_type != null orderby r.contactid select new opportunities { opporunity = r.new_opportunitynumber, //region =getaccountregionsbyid(a.new_region.value), accountid = r.customerid.id, topic = r.name, status = r.statecode.value.tostring(), pcustomer = r.customerid.name, estreve = (decimal)r.estimatedvalue.value, owner = r.ownerid.name, salesstagecode = r.salesstagecode.value, pipelinephase = r.stepname, opptype = getalloptionsetvalues(r.logicalname, "new_sf_recordtype", r.new_sf_recordtype.value), subtype = getalloptionsetvalues(r.logicalname, "new_type", r.new_type == null ? default(int) : r.new_type.value), estclosedate = r.estimatedclosedate.value, actualrev = (microsoft.xrm.sdk.money)r.actualvalue, probability = r.closeprobability.value, weighedrev = (decimal)r.new_weightedvalue.value, email = z.emailaddress1, createdon = r.createdon.value, modifiedby = r.modifiedby.name, modifiedon = r.modifiedon.value }).tolist(); foreach (opportunities o in query) { o.region = (from d in context.createquery<account>() d.accountid == o.accountid select getalloptionsetvalues(d.logicalname, "new_region", d.new_region.value)).firstordefault(); } return query; } }
Comments
Post a Comment