c# - CRM plugin PreImage not updating related entity -


i'm new developing i've encountered problem when creating plugin dynamics crm. plugin supposed render parentcustomerid field null on contact entity when account entity linked updated when field primarycontactid updated else, either null on linked contact.

with code have written no errors thrown , code executed successful parentcustomerid field still contains account linked when should remove link.

here code have currently:

    public void execute(iserviceprovider serviceprovider)     {                    itracingservice tracingservice = (itracingservice)serviceprovider.getservice(typeof(itracingservice));               //obtain execution context             ipluginexecutioncontext context = (ipluginexecutioncontext)serviceprovider.getservice(typeof(ipluginexecutioncontext));              //obtain organizational services             iorganizationservicefactory servicefactory = (iorganizationservicefactory)serviceprovider.getservice(typeof(iorganizationservicefactory));             iorganizationservice service = servicefactory.createorganizationservice(context.userid);              entityreference prepcid;             entity preimage;             // inputparameters collection contains data passed in message request.             if (context.inputparameters.contains("target") &&                 context.inputparameters["target"] entity)             {                 // obtain image entity pre entity images.                 tracingservice.trace                     ("trace1: getting target entity input parameters.");                 preimage = (entity)context.inputparameters["target"];                  // verify target entity represents account.                 // if not, plug-in not registered correctly.                 tracingservice.trace                    ("trace2: verifying target entity represents account.");                 if (preimage.logicalname == "account")                 {                     if (preimage.attributes.contains("primarycontactid"))                     {                         tracingservice.trace                             ("trace3: setting primary contact id in prepcid.");                     //prepcid = (entityreference)preimage.attributes["primarycontactid"];                     prepcid = (entityreference)preimage["primarycontactid"];                          tracingservice.trace                             ("trace4: primary contact name: " + prepcid.name + " creating variable stores contact using prepcid.");                         entity contacttoremovereference = service.retrieve("contact", prepcid.id, new columnset("parentcustomerid")) entity;                         tracingservice.trace                             ("trace5: removes id: " + prepcid.id + " of parentcustomerid.");                         contacttoremovereference.attributes["parentcustomerid"] = null;                          service.update(contacttoremovereference);                         tracingservice.trace                             ("trace6: execution successful.");                     }                 }           } 

}

if solve issue me, great thanks.

you populating entity variable preimage primary entity in input parameters. think should pre image like:

entity preimage; if (context.preentityimages.contains("yourpreimagename") && context.preentityimages["yourpreimagename"] != null) {     preimage = context.preentityimages["yourpreimagename"]; } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -