如何允许 CRM 插件处理多个事件消息
How To Allow CRM Plugin To Handle Multiple Event Messages
我需要创建一个插件来触发机会实体的创建、更新和删除事件。
我可以在一个插件中完成这些吗?如果是这样,我该怎么做?
您的插件必须实现 Microsoft.Xrm.Sdk.IPlugin
接口,该接口只有一个实现方法 Execute
。在您的 Execute
方法中,您需要检查 IPluginExecutionContext 的 MessageName
属性 并检查触发插件的事件类型。您还需要通过插件注册工具为每种消息类型 (Create/Update/Delete) 注册插件。
这是我个人的 OOB 消息类型列表,用于与 MessageName
:
进行比较
AddItem,
AddListMembers,
AddMember,
AddMembers,
AddPrincipalToQueue,
AddPrivileges,
AddProductToKit,
AddRecurrence,
AddToQueue,
AddUserToRecordTeam,
Assign,
AssignUserRoles,
Associate,
BackgroundSend,
Book,
Cancel,
CheckIncoming,
CheckPromote,
Clone,
Close,
CopyDynamicListToStatic,
CopySystemForm,
Create,
CreateException,
CreateInstance,
Delete,
DeleteOpenInstances,
DeliverIncoming,
DeliverPromote,
DetachFromQueue,
Disassociate,
Execute,
ExecuteById,
Export,
ExportAll,
ExportCompressed,
ExportCompressedAll,
GenerateSocialProfile,
GrantAccess,
Handle,
Import,
ImportAll,
ImportCompressedAll,
ImportCompressedWithProgress,
ImportWithProgress,
LockInvoicePricing,
LockSalesOrderPricing,
Lose,
Merge,
ModifyAccess,
PickFromQueue,
Publish,
PublishAll,
QualifyLead,
Recalculate,
ReleaseToQueue,
RemoveFromQueue,
RemoveItem,
RemoveMember,
RemoveMembers,
RemovePrivilege,
RemoveProductFromKit,
RemoveRelated,
RemoveUserFromRecordTeam,
RemoveUserRoles,
ReplacePrivileges,
Reschedule,
Retrieve,
RetrieveExchangeRate,
RetrieveFilteredForms,
RetrieveMultiple,
RetrievePersonalWall,
RetrievePrincipalAccess,
RetrieveRecordWall,
RetrieveSharedPrincipalsAndAccess,
RetrieveUnpublished,
RetrieveUnpublishedMultiple,
RetrieveUserQueues,
RevokeAccess,
Route,
RouteTo,
Send,
SendFromTemplate,
SetRelated,
SetState,
SetStateDynamicEntity,
TriggerServiceEndpointCheck,
UnlockInvoicePricing,
UnlockSalesOrderPricing,
Update,
ValidateRecurrenceRule,
Win
是的,您可以使用相同的插件在创建、更新和删除时执行它
按如下方式编写你的插件..
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.MessageName == "Create")
{
//write the logic what you want this plugin to do on Create
}
if (context.MessageName == "Update")
{
//write the logic what you want this plugin to do on Update
}
if (context.MessageName == "Delete")
{
//write the logic what you want this plugin to do on Delete
}
}
Register your plugin on Create,Update,Delete for Oppertunity Entity using Plugin registration
tool
它应该可以工作
我需要创建一个插件来触发机会实体的创建、更新和删除事件。
我可以在一个插件中完成这些吗?如果是这样,我该怎么做?
您的插件必须实现 Microsoft.Xrm.Sdk.IPlugin
接口,该接口只有一个实现方法 Execute
。在您的 Execute
方法中,您需要检查 IPluginExecutionContext 的 MessageName
属性 并检查触发插件的事件类型。您还需要通过插件注册工具为每种消息类型 (Create/Update/Delete) 注册插件。
这是我个人的 OOB 消息类型列表,用于与 MessageName
:
AddItem,
AddListMembers,
AddMember,
AddMembers,
AddPrincipalToQueue,
AddPrivileges,
AddProductToKit,
AddRecurrence,
AddToQueue,
AddUserToRecordTeam,
Assign,
AssignUserRoles,
Associate,
BackgroundSend,
Book,
Cancel,
CheckIncoming,
CheckPromote,
Clone,
Close,
CopyDynamicListToStatic,
CopySystemForm,
Create,
CreateException,
CreateInstance,
Delete,
DeleteOpenInstances,
DeliverIncoming,
DeliverPromote,
DetachFromQueue,
Disassociate,
Execute,
ExecuteById,
Export,
ExportAll,
ExportCompressed,
ExportCompressedAll,
GenerateSocialProfile,
GrantAccess,
Handle,
Import,
ImportAll,
ImportCompressedAll,
ImportCompressedWithProgress,
ImportWithProgress,
LockInvoicePricing,
LockSalesOrderPricing,
Lose,
Merge,
ModifyAccess,
PickFromQueue,
Publish,
PublishAll,
QualifyLead,
Recalculate,
ReleaseToQueue,
RemoveFromQueue,
RemoveItem,
RemoveMember,
RemoveMembers,
RemovePrivilege,
RemoveProductFromKit,
RemoveRelated,
RemoveUserFromRecordTeam,
RemoveUserRoles,
ReplacePrivileges,
Reschedule,
Retrieve,
RetrieveExchangeRate,
RetrieveFilteredForms,
RetrieveMultiple,
RetrievePersonalWall,
RetrievePrincipalAccess,
RetrieveRecordWall,
RetrieveSharedPrincipalsAndAccess,
RetrieveUnpublished,
RetrieveUnpublishedMultiple,
RetrieveUserQueues,
RevokeAccess,
Route,
RouteTo,
Send,
SendFromTemplate,
SetRelated,
SetState,
SetStateDynamicEntity,
TriggerServiceEndpointCheck,
UnlockInvoicePricing,
UnlockSalesOrderPricing,
Update,
ValidateRecurrenceRule,
Win
是的,您可以使用相同的插件在创建、更新和删除时执行它
按如下方式编写你的插件..
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.MessageName == "Create")
{
//write the logic what you want this plugin to do on Create
}
if (context.MessageName == "Update")
{
//write the logic what you want this plugin to do on Update
}
if (context.MessageName == "Delete")
{
//write the logic what you want this plugin to do on Delete
}
}
Register your plugin on Create,Update,Delete for Oppertunity Entity using Plugin registration tool
它应该可以工作