c# - CRM Dynamics Plugin on Update not Working? -
i have crm dynamics plugin fires on update of boolean change, fails fire when select yes on 2 option control, please find code below , advice may going wrong.
namespace webcall.plugin { public class webcalltrigger : iplugin { /// <summary> /// plugin initiate web call crm using marusip api /// </summary> /// <param name="serviceprovider"></param> public void execute(iserviceprovider serviceprovider) { ipluginexecutioncontext context = (ipluginexecutioncontext)serviceprovider.getservice(typeof(ipluginexecutioncontext)); if (context == null) { throw new argumentnullexception("localcontext"); } iorganizationservicefactory servicefactory = (iorganizationservicefactory)serviceprovider.getservice(typeof(iorganizationservicefactory)); iorganizationservice service = servicefactory.createorganizationservice(context.initiatinguserid); if (context.inputparameters.contains("target") && context.inputparameters["target"] entity) { //initaialize entity entity phonecallentity = (entity)context.inputparameters["target"]; if (phonecallentity.logicalname != contact.entitylogicalname) return; //ensure plugin fires on create operaton if (context.messagename == "update") { try { if (phonecallentity.attributes.contains("new_dialnumber")) phonecallentity["new_dialnumber"] = true; string numbertocall; // = phonecallentity.contains("telephone1") ? phonecallentity["telephone1"].tostring() : null; if (phonecallentity.contains("telephone1")) { numbertocall = phonecallentity.attributes["telephone1"].tostring(); } else { numbertocall = phonecallentity.attributes["mobilephone"].tostring(); } string receivecallon = phonecallentity.contains("new_receivecallon") ? phonecallentity["new_receivecallon"].tostring() : null; string apikey = phonecallentity.attributes.contains("new_apikey") ? phonecallentity.attributes["new_apikey"].tostring() : null; int fid = phonecallentity.attributes.contains("new_fid") ? (int)phonecallentity.attributes["new_fid"] : 0; //service.update(phonecallentity); //create new instance of webcallservice , call webcall method webcallservice webcallservice = new webcallservice(); webcallservice.webcall(numbertocall, receivecallon, apikey, fid); }
in case telephone1 or mobilephone fields not updated - target referring not contain mentioned fields. suggestion data pre-image. can check article - https://deepakexploring.wordpress.com/2011/02/04/preentityimages-and-postentityimages-in-crm-5-0-2011/
Comments
Post a Comment