plug-in for when an email to send update the fields in the record
-
2012년 5월 7일 월요일 오후 2:21
hello everyone i created a plug-in when an email is sent i required to update some fields in the record for that i created a plug-in that is
i found some error in this but am not able to identify itplease
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using System.ServiceModel;
using System.Runtime.Serialization;
using Microsoft.Crm.Sdk.Messages;
namespace setupdate
{
public class Update : IPlugin
{
public void Execute(IServiceProvider serviceprovider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceprovider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceprovider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = servicefactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (context.PrimaryEntityName == "email" && context.MessageName == "SetStateDynamicEntity" || context.MessageName == "SetState" || context.MessageName == "send")
{
if (context.PostEntityImages["PostImage"].Attributes.Contains("regardingobjectid")
// && context.PostEntityImages["PostImage"].Attributes.Contains("statecode")
&& context.PostEntityImages["PostImage"].Attributes.Contains("statuscode")
&& ((EntityReference)context.PostEntityImages["PostImage"]["regardingobjectid"]).LogicalName == "lead" // Update the entity type you want to take effect or remove this line if you want to trigger for all types
// && ((OptionSetValue)(context.PostEntityImages["PostImage"]["statecode"])).Value == 1 // Completed
&& ((OptionSetValue)(context.PostEntityImages["PostImage"]["statuscode"])).Value == 6 // Sent
)
{
Entity regardingRecord = new Entity((((EntityReference)context.PostEntityImages["PostImage"]["regardingobjectid"]).LogicalName));
regardingRecord.Id = ((EntityReference)context.PostEntityImages["PostImage"]["regardingobjectid"]).Id;
regardingRecord["new_assignedto"] = 0;
regardingRecord["description"] = "test job docket";
regardingRecord["new_jobstatus"] = 1;
service.Update(regardingRecord);
please i need to develop this plug-inpleasede help me
ms crm
모든 응답
-
2012년 5월 11일 금요일 오전 12:07
Hi,
I think the problem is with this line of code
if (context.PrimaryEntityName == "email" && context.MessageName == "SetStateDynamicEntity" || context.MessageName == "SetState" || context.MessageName == "send")
It should be
if (context.PrimaryEntityName == "email" && (context.MessageName == "SetStateDynamicEntity" || context.MessageName == "SetState" || context.MessageName == "Send"))
I hope this helps. If my response answered your question, please mark the response as an answer.
Dimaz Pramudya - CRM Developer - CSG (Melbourne) www.xrmbits.com http://twitter.com/xrmbits
- 답변으로 제안됨 Dimaz Pramudya (www.xrmbits.com) 2012년 5월 11일 금요일 오전 12:07