c# - CRM 2011 update incident when email arrives -
in crm when emails arrive , have tracking token in them automatically set regarding field incident (or whatever relate to)
unfortunately record wall isn't updated info if following case nothing alerts new activity.
i want write plugin on email or incident (or both) updates record wall , creates task follow on email in 3 days.
i'm looking @ sdk , can't see appropriate event in pipe line work out when email is/has regarding field set on arrival in crm.
the crm email creation life-cycle not described in documentation. [shakes fist]
extra things bothering me
i can't seem include reference typed email, post or case (driving me crazy)
testing hard (harder should be)
edit here current code
namespace assembly.plugins { using system; using system.servicemodel; using microsoft.xrm.sdk; using microsoft.xrm.sdk.query; /// <summary> /// postemaildeliverincoming plugin. /// </summary> public class postemaildeliverincoming : plugin { /// <summary> /// initializes new instance of <see cref="postemaildeliverincoming"/> class. /// </summary> public postemaildeliverincoming() : base(typeof(postemaildeliverincoming)) { registeredevents.add(new tuple<int, string, string, action<localplugincontext>>(40, "deliverincoming", "email", executepostemaildeliverincoming)); // note : can register more events here if plugin not specific individual entity , message combination. // may need update registerfile.crmregister plug-in registration file reflect change. } protected void executepostemaildeliverincoming(localplugincontext localcontext) { if (localcontext == null) { throw new argumentnullexception("localcontext"); } //extract tracing service use in debugging sandboxed plug-ins. itracingservice tracingservice = localcontext.tracingservice; // obtain execution context service provider. ipluginexecutioncontext context = localcontext.pluginexecutioncontext; // obtain organization service reference. var service = localcontext.organizationservice; // inputparameters collection contains data passed in message request. if (!context.inputparameters.contains("target") || !(context.inputparameters["target"] entity)) return; // obtain target entity input parmameters. var target = (entity)context.inputparameters["target"]; // verify target entity represents account. // if not, plug-in not registered correctly. if (target.logicalname != "email") return; if((string)target["direction"] != "incoming") return; if (target["regardingobjectid"] == null) return; try { // if not case don't care var incident = service.retrieve("incident", (guid)target["regardingobjectid"], new columnset(true)); if (incident == null) return; var post = new entity("post"); post["regardingobjectid"] = target["regardingobjectid"]; post["source"]=new optionsetvalue(0); post["text"] = string.format("a new email has arrived."); // create task in microsoft dynamics crm. tracingservice.trace("followupplugin: creating post."); service.create(post); // create task activity follow account customer in 7 days. var followup = new entity("task"); followup["subject"] = "follow incoming email."; followup["description"] = "an email arrived assigned case please follow up."; followup["scheduledstart"] = datetime.now.adddays(3); followup["scheduledend"] = datetime.now.adddays(3); followup["category"] = context.primaryentityname; // refer email in task activity. if (context.outputparameters.contains("id")) { var regardingobjectid = new guid(context.outputparameters["id"].tostring()); followup["regardingobjectid"] = new entityreference("email", regardingobjectid); } // create task in microsoft dynamics crm. tracingservice.trace("followupplugin: creating task activity."); service.create(followup); } catch (faultexception<organizationservicefault> ex) { throw new invalidpluginexecutionexception("an error occurred in follupupplugin plug-in.", ex); } catch (exception ex) { tracingservice.trace("followupplugin: {0}", ex.tostring()); throw; } } } }
i've been fighting exact same issue , came across post. thought i'd post solution (if still need it) , else comes across issue in future.
here's solution arrived at: - using plugin registration tool register new image on appropriate step( stage = "40", messagename = "deliverincoming") - set new image post image - in plugin fetch post image's entity id:
guid emailid = context.postentityimages["postimage"].id; entity emailfromretrieve = localcontext.organizationservice.retrieve( "email", emailid, new microsoft.xrm.sdk.query.columnset(true)); email email = emailfromretrieve.toentity<email>(); if (email.regardingobjectid == null) { return; } var regardingobject = email.regardingobjectid;
hope helps!
Comments
Post a Comment