开发者

Is there a way to differentiate from SSIS execution vs web UI execution in a CRM 4.0 plugin?

开发者 https://www.devze.com 2023-03-29 08:44 出处:网络
Here\'s the setup: Custom_entity takes a few inputs from a user, calculates a number, and compares it with a total stored in our database to get an overall percentage.The total is updated every week.

Here's the setup:

Custom_entity takes a few inputs from a user, calculates a number, and compares it with a total stored in our database to get an overall percentage. The total is updated every week. To update every user's custom_entities to reflect the new totals and percentages of those totals, I've created an SSIS package to run every week. Of course I'm being nice and compliant, so I use the API to hit the CRM webservice to update the custom_entities.

However, users also want to see a real-time update of their custom_entity, so I created a plugin that, on a custom_entity update will re-calculate their numbers, check for updates of the "total" in the database, and update the percentage correlating the all the other updates.

Perhaps you're seeing the problem now...

  • When a user updates from the web the update plugin fires f开发者_高级运维or THAT instance of the custom_entity, they get instant feedback, see their numbers and are happy.
  • When the SSIS package runs, the update plugin fires for ALL custom_entity rows being updated...

My question: Is there a way (perhaps by looking at context) that I can tell whether the plugin was invoked via the SSIS job or the web, and then just exit out of the plugin?

Currently there are few rows, and no real performance hit, but it's obvious that this is certainly poor programming and unneeded CPU/bandwidth usage (the plugin itself hits the webservice several times over the course of execution). I could short-circuit the plugin by looking for a specific property that will only be present when the SSIS package calls the plugin, but I'd like to find a better way than that.

Thank you!


You could take a look at the context.CallerOrigin property. It will show you the source, which triggered the message. In your case you should check for WebServiceApi

using System;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
 
public class OnlinePlugin : IPlugin
{
  public void Execute(IPluginExecutionContext context)
  {
     // Check to see if this is a playback context.
     CallerOrigin callerOrigin = context.CallerOrigin;
  
     if (callerOrigin is OfflineOrigin)
     {
       // This plug-in was fired from the playback queue after the user
       // selected to go online within Microsoft Dynamics CRM for Outlook.
       return;
     }
     else
     {
       // Do something here.
     }
  }
}

Take a look at my article Who triggered my plugin?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号