简体   繁体   English

CRM 2013-插件执行(后期操作)什么时候发生?

[英]CRM 2013 - Plugin Execution (Post Operation) What happens and when?

I have a system configuration entity where I store credentials of a Web Service. 我有一个系统配置实体,在其中存储Web服务的凭据。 I need to encrypt the password field (new_SharePointServicePassword) and I want my plugin to do the encryption. 我需要加密密码字段(new_SharePointServicePassword),并且我希望我的插件进行加密。

So, I have created a new assembly with the following events registered. 因此,我创建了一个新的程序集,并注册了以下事件。

base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "new_systemconfiguration", new Action<LocalPluginContext>(ExecutePostSystemConfigurationCreate)));
base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "new_systemconfiguration", new Action<LocalPluginContext>(ExecutePostSystemConfigurationCreate)));

My plugin code is as below. 我的插件代码如下。

string plainTextPassword = SystemConfiguration.new_SharePointServicePassword;
string encryptedPassword;
this.TracingService.Trace("Generating Keys");
Encryption encryption = new Encryption(localContext.PluginExecutionContext.OrganizationId.ToString());
this.TracingService.Trace("Generating Keys - Completed");
if (!string.IsNullOrEmpty(plainTextPassword))
{
    this.TracingService.Trace("Encrypting password");
    encryptedPassword = encryption.Encrypt(plainTextPassword);
    this.TracingService.Trace("Encrypting password - Completed");
    SystemConfiguration.new_SharePointServicePassword = encryptedPassword;
    localContext.OrganizationService.Update(SystemConfiguration);
}

The steps registered against the Plugin are for Post Operation for both Create and Update messages. 针对插件注册的步骤适用于创建和更新消息的后期操作。 The Update message is filtered on the new_SharePointServicePassword attribute. 更新消息在new_SharePointServicePassword属性上进行过滤。

Questions 问题

  1. Why is the call localContext.OrganizationService.Update(SystemConfiguration); 为什么调用localContext.OrganizationService.Update(SystemConfiguration); required? 需要? Is it because, my plugin executes after the changes have been committed to the database? 是因为我的插件在更改提交到数据库后执行?
  2. Can I instead modify the step as Pre Operation on the Update message? 我可以改为将步骤修改为“更新前的操作”吗? I tried this, but my plugin never fired? 我试过了,但是我的插件没被触发? Why did it not fire? 为什么不开火?
  3. Is there any way that I can do this better? 有什么办法可以做得更好?

I would recommend you to run the plugin on Pre Operation . 我建议您在Pre Operation上运行插件。 Because when you enter the password through UI, it will save the unencrypted password first. 因为当您通过UI输入密码时,它将首先保存未加密的密码。 User will have to refresh to see the encryption. 用户将必须刷新才能看到加密。 Also if you have auditing enabled on password field. 另外,如果您在密码字段上启用了审核。 It will show the unencrypted password in Audit log. 它将在审核日志中显示未加密的密码。 On Pre Operation you don't need following line: 在“ Pre Operation您不需要执行以下Pre Operation

localContext.OrganizationService.Update(SystemConfiguration);

Make sure that you replace 40 with 20 in your code. 确保在代码中将40替换为20

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM