簡體   English   中英

批量刪除不會在CRM動態中觸發插件

[英]Bulk delete does not fire the plugin in CRM dynamics

我想在Microsoft CRM dynamics 2013中觸發批量刪除插件。我創建了一個自定義實體,我的插件指向此自定義實體的刪除操作。 我按如下方式配置了插件注冊:

   Message :    "delete"
   Primary entity :     "my custom entity",
   Run in User's Context :    "Calling User",
   Event pipeline :    "Pre operation",
   Execution mode :    "synchronous"

批量刪除過程不會觸發插件。 它沒有拋出錯誤。
但是插件可以通過手動刪除操作觸發。但是我想從任何系統事件中觸發插件作為計划(批量刪除)
請幫我解決這個問題。

這是我的代碼:

 Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
 serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

  if (context.Depth == 1)
  {
      IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
      IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);

      EntityReference entity = (EntityReference)context.InputParameters["Target"];

      DateTime dtToday = DateTime.Now;
      DateTime toDate = dtToday.AddMonths(-1);

      QueryExpression qe = new QueryExpression("contact");
      qe.ColumnSet = new ColumnSet(new String[] { "birthdate", "firstname", "address1_name" ,"new_lastapptdate" });
      qe.Criteria.AddCondition("new_lastapptdate", ConditionOperator.LessEqual, toDate);

      EntityCollection collection = service.RetrieveMultiple(qe);

      foreach (Entity contact in collection.Entities)
      {

      }

     try
     {
         var factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
         Entity Ageentity = new Entity("new_agecalc");
         Ageentity.Attributes.Add("new_name", "AgecalcTest");
         service.Create(Ageentity);
     }
     catch (Exception ex)
     {
         throw new InvalidPluginExecutionException("An error ", ex);
     }
  }

}

在您的代碼中,您正在檢查上下文深度是否等於1.在批量刪除期間,它已經是作業的一部分,因此深度將大於1.如果刪除此檢查,您的插件應該可以正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM