2016-11-25 18 views
0

私は処理が必要な特定の状況があります。私は、インボイスの詳細が作成または更新されたときにインボイスの特定のロールアップフィールドをリフレッシュするプラグインを持っています。 これで、請求書の詳細が削除されたら、そのフィールドを更新する必要があります。 Dynamics CRMプラグイン - 削除時のロールアップをリフレッシュ


は、この問題を分析し、私は請求書の詳細レコードがまだ削除されていないので、私は前の操作にロールアップフィールドを更新することができないことに気づき、それがなくなっているので、ポスト操作に私は、その特定のレコードから請求書GUIDを取得することはできません。ここで

/作成、更新にロールアップリフレッシュを処理するコードの一部:

Entity invoiceDetail = service.Retrieve("invoicedetail", targetId, new ColumnSet(true)); 
Guid invoiceID = ((EntityReference)invoiceDetail["invoiceid"]).Id; 
if (targetEntity.Attributes.Contains("extendedamount")) 
{ 
    Entity myEntity = service.Retrieve("invoice", invoiceID, new ColumnSet(true)); 
    CalculateRollupFieldRequest rollupRequest = new CalculateRollupFieldRequest 
    { 
     Target = new EntityReference("invoice", invoiceID), 
     FieldName = "detailamount" 
    }; 
    CalculateRollupFieldResponse response = (CalculateRollupFieldResponse)service.Execute(rollupRequest); 
    myEntity = response.Entity; 
    service.Update(myEntity); 
} 

は、あなたが何か提案はありますか?私はこれ以上怒っつもりですし、何も考えることができない...

+0

使用しているCRMのバージョンは何ですか? – pen2

+0

私はCRMを使用しています2016 – bocasa

+0

bocasaなぜpre-eventを使うことができないのだろうと思っています。レコードはこの後に削除され、レコードが削除操作で失敗するとロールバックされます。 – Sxntk

答えて

4

あなたはプレイベントでGUIDを取得することができ、およびイベントをポストするためにそれを渡す - MSDNからMSDN documentation

サンプルコード:

using System; 

// Microsoft Dynamics CRM namespace(s) 
using Microsoft.Xrm.Sdk; 

namespace Microsoft.Crm.Sdk.Samples 
{ 
    /// <summary> 
    /// A plug-in that sends data to another plug-in through the SharedVariables 
    /// property of IPluginExecutionContext. 
    /// </summary> 
    /// <remarks>Register the PreEventPlugin for a pre-operation stage and the 
    /// PostEventPlugin plug-in on a post-operation stage. 
    /// </remarks> 
    public class PreEventPlugin : IPlugin 
    { 
     public void Execute(IServiceProvider serviceProvider) 
     { 
      // Obtain the execution context from the service provider. 
      Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext) 
       serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext)); 

      // Create or retrieve some data that will be needed by the post event 
      // plug-in. You could run a query, create an entity, or perform a calculation. 
      //In this sample, the data to be passed to the post plug-in is 
      // represented by a GUID. 
      Guid contact = new Guid("{74882D5C-381A-4863-A5B9-B8604615C2D0}"); 

      // Pass the data to the post event plug-in in an execution context shared 
      // variable named PrimaryContact. 
      context.SharedVariables.Add("PrimaryContact", (Object)contact.ToString()); 
     } 
    } 

    public class PostEventPlugin : IPlugin 
    { 
     public void Execute(IServiceProvider serviceProvider) 
     { 
      // Obtain the execution context from the service provider. 
      Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext) 
       serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext)); 

      // Obtain the contact from the execution context shared variables. 
      if (context.SharedVariables.Contains("PrimaryContact")) 
      { 
       Guid contact = 
        new Guid((string)context.SharedVariables["PrimaryContact"]); 

       // Do something with the contact. 
      } 
     } 
    } 
} 
+0

いいね!現時点でこれを実装すると、どのように進行しているかをお知らせします... – bocasa

+0

が実装され、テストされました。 – bocasa

関連する問題