2016-10-18 4 views
-1

私は、見積エンティティで更新が行われるたびに、カスタムフィールドに基づいて見積の価格を計算するプラグインを作成しました。私は、見積エンティティの前処理更新でプラグインを実行しました。私のプラグインをdebbugしようとしましたが、null値を取得します。たとえば、フィールド "edm_CashAmount"の値には5000が含まれていますが、コードはnullを取得しました。親切に以下に助言してください。前もって感謝します。Dynamics CRMプラグイン - 事前操作更新

namespace CRMPlugins.Plugins 
{ 
    using System; 
    using System.ServiceModel; 
    using Microsoft.Xrm.Sdk; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using Microsoft.Crm.Sdk.Messages; 

    public class PrequoteUpdate : Plugin 
    { 

     public PrequoteUpdate() 
      : base(typeof(PrequoteUpdate)) 
     { 
      base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Update", "quote", new Action<LocalPluginContext>(ExecutePrequoteUpdate))); 

     } 

     protected void ExecutePrequoteUpdate(LocalPluginContext localContext) 
     { 
      if (localContext == null) 
      { 
       throw new ArgumentNullException("localContext"); 
      } 

      Entity entity = null; 

      if (localContext.PluginExecutionContext.InputParameters.Contains("Target") && localContext.PluginExecutionContext.InputParameters["Target"] is Entity) 
      { 
       entity = (Entity)localContext.PluginExecutionContext.InputParameters["Target"]; 
      } 
      else 
      { 
       return; 
      } 
      decimal instotal = 0; 
      Quote quote = entity.ToEntity<Quote>(); 
      using (GeneratedEntities orgContext = new GeneratedEntities(localContext.OrganizationService)) 
      { 
       var installements = (from b in orgContext.edm_installementSet 
            where b.GetAttributeValue<Guid>("edm_quote") == quote.QuoteId 
            select b); 

       foreach (var c in installements) 
       { 

        if (c.edm_Amount != null) 
        { 
         instotal += (decimal)c.new_Decimal; 

        } 
       } 
      } 
      decimal cash = 0; 
      if (quote.edm_CashAmount != null) 
      { 
       cash = Convert.ToDecimal(quote.GetAttributeValue<Money>("edm_cashamount").Value); 
      } 
      decimal check = 0; 
      if (quote.edm_CheckAmount != null) 
      { 
       check = Convert.ToDecimal(quote.GetAttributeValue<Money>("edm_checkamount").Value); 
      } 
      decimal credit = 0; 
      if (quote.edm_CreditCardAmount != null) 
      { 
       credit = Convert.ToDecimal(quote.GetAttributeValue<Money>("edm_creditcardamount").Value); 
      } 
      decimal gift = 0; 
      if (quote.new_GiftCard != null) 
      { 
       gift = Convert.ToDecimal(quote.GetAttributeValue<Money>("new_giftcard").Value); 
      } 
      decimal total = 0; 
      if (quote.TotalLineItemAmount != null) 
      { 
       total = Convert.ToDecimal(quote.GetAttributeValue<Money>("totallineitemamount").Value); 
      } 

      decimal currentbalane = 0; 
      if (quote.edm_CurrentBalane != null) 
      { 
       currentbalane = Convert.ToDecimal(quote.GetAttributeValue<Money>("edm_currentbalane").Value); 
      } 


      decimal DiscAmount = 0; 
      if (quote.DiscountAmount != null) 
      { 
       DiscAmount = Convert.ToDecimal(quote.GetAttributeValue<Money>("discountamount").Value); 

      } 

      decimal totalafterdiscount = total - DiscAmount; 
      decimal tax = (totalafterdiscount * 10)/100; 
      decimal totalwithvat = totalafterdiscount + tax; 
      decimal paidamount = cash + check + credit + gift + instotal; 
      decimal remainingamount = totalwithvat - paidamount; 
      quote["edm_cashamount_1"] = new Money(tax); 
      quote["edm_totaltax"] = new Money(tax); 
      quote["edm_paidamount"] = new Money(paidamount); 
      quote["edm_remainingamount"] = new Money(remainingamount); 
      quote["edm_total"] = new Money(totalwithvat); 
      quote["edm_totalinstallements"] = new Money(instotal); 
      quote["edm_checkamount_1"] = new Money(totalwithvat); 

     } 
    } 
} 

答えて

0

更新プラグインの場合、値が変更されていない場合、ターゲットエンティティには表示されません。したがって、これらの値を含むプレエンティティイメージを作成するか、変更後のエンティティの状態を表示するポストエンティティイメージを作成することができます

関連する問題