c# - CRM Dynamics plugin code issue 2015 -
i'm trying create plugin microsoft crm dynamics 2015 (version 7.0.2), it's not working. plugin run when case created , attemp recover contract information account.
i have following code, it's not working(contract information not saved on case/incident).
edit
i update code, fails, doesn't give clear error on system job or when debug using plugin registration tool.
system job error message: system.servicemodel.quotaexceededexception: microsoft dynamics crm has experienced error. reference number administrators or support: #1c10449a
debuging visual studio , plugin registration tool goes until tries call update method, says incident not exist, since syncrhonous plugin incident not created(only way log able debug found).
public class casecontractfill : iplugin { contract checkforcontract(guid accountid, iorganizationservice service) { queryexpression accountcontractquery = new queryexpression { entityname = contract.entitylogicalname, columnset = new columnset(true), criteria = new filterexpression { conditions = { new conditionexpression { attributename = "accountid", operator = conditionoperator.equal, values = { accountid } } } } }; datacollection<entity> accountcontracts = service.retrievemultiple(accountcontractquery).entities; //check if account has contract , return if (accountcontracts.count > 0) { return (contract)accountcontracts[0]; } //retrieves account account account = (account)service.retrieve(account.entitylogicalname, accountid, new columnset(true)); //check if account has parent , call method again parent if (account.parentaccountid != null) { checkforcontract(account.parentaccountid.id, service); } //if no contract and/or no parent returns null return null; } contractdetail checkforcontractline(guid contractid, iorganizationservice service) { queryexpression accountcontractquery = new queryexpression { entityname = contractdetail.entitylogicalname, columnset = new columnset(true), criteria = new filterexpression { conditions = { new conditionexpression { attributename = "contractid", operator = conditionoperator.equal, values = { contractid } } } } }; datacollection<entity> contractlines = service.retrievemultiple(accountcontractquery).entities; return (contractdetail)contractlines[0]; } public void execute(iserviceprovider serviceprovider) { itracingservice tracer = (itracingservice)serviceprovider.getservice(typeof(itracingservice)); ipluginexecutioncontext context = (ipluginexecutioncontext)serviceprovider.getservice(typeof(ipluginexecutioncontext)); iorganizationservicefactory factory = (iorganizationservicefactory)serviceprovider.getservice(typeof(iorganizationservicefactory)); iorganizationservice service = factory.createorganizationservice(context.userid); try { entity entity = (entity)context.inputparameters["target"]; incident incident = (incident)entity.toentity<incident>(); contract contract = checkforcontract(incident.customerid.id, service); if (contract != null) { incident.contractid = contract.toentityreference(); contractdetail contractline = checkforcontractline(contract.id, service); incident.contractdetailid = contractline.toentityreference(); service.update(incident); } } catch (exception e) { throw new invalidpluginexecutionexception(e.message); } } }
"contractid" being incorrectly assigned.
if (contract != null) { incident.contractid = contract.toentityreference(); service.update(incident); }
Comments
Post a Comment