再定式化された質問 (4 月 24 日):
VS2012 用の CRM 開発者ツールキットを使用して、CRM2011 プラグインを作成しています。プラグインはCREATE
、「Invoice Product」エンティティのメッセージに登録されます。Pipeline-Stage は運用後であり、実行は同期的です。を含む投稿画像に登録しますbaseamount
。
ツールキットは、次のような実行関数を作成します。
protected void ExecutePostInvoiceProductCreate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
IPluginExecutionContext context = localContext.PluginExecutionContext;
Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;
}
運用後の段階なので、 baseamount
inの値はpostImageEntity
ユーザー入力からすでに計算されているはずですよね? ただし、 の値baseamount
はpostImageEntity
ゼロです。baseamount
同じことが、次のコードを使用して取得するターゲット エンティティの値にも当てはまります。
Entity targetEntity = (context.InputParameters != null && context.InputParameters.Contains("Target")) ? (Entity)context.InputParameters["Target"] : null;
以下のような取得リクエストを使用して、正しい値を取得していますbaseamount
:
Entity newlyCreated = service.Retrieve("invoicedetail", targetEntity.Id, new ColumnSet(true));
decimal baseAmount = newlyCreated.GetAttributeValue<Money>("baseamount").Value;
この問題は、更新イベントの運用後の段階では発生しません。
なぜこれが当てはまるのかについて、あなたのアイデア/説明/提案を聞いてうれしいです...
(詳細情報: リモート デバッグ、分離モードなし、データベースに格納されたプラグイン)
元の質問:
請求書の詳細が作成されたときに支払われる税額を計算することになっている CRM 2011 のプラグインに取り組んでいます。この目的のために、運用後の段階でエンティティ イメージからbaseamount
新しく作成されたエンティティを取得しようとしています。invoicedetail
私が理解している限り、投稿エンティティ イメージは、新しい請求書の詳細が作成された後のデータベース内のエンティティのスナップショットです。したがって、新しく作成された請求書の詳細のすべてのプロパティが含まれている必要があります。
登録したエイリアス (「postImage」) を持つエンティティを含む IPluginExecutionContext の「postentityimages」プロパティを取得しています。この "postImage" エンティティには "baseamount" のキーが含まれていますが、その値は 0 です。なぜそうなのか、そしてそれに対して何ができるのかを理解してくれる人はいますか?
(postImage には、登録したエンティティのすべてではなくサブセットのみが含まれていることにも気付きました。)
コードは次のようになります。
protected void ExecutePostInvoiceProductCreate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
// Get PluginExecutionContext to obtain PostEntityImages
IPluginExecutionContext context = localContext.PluginExecutionContext;
// This works: I get a postImage that is not null.
Entity postImage = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;
// Here is the problem: There is a "baseamount" key in the postImage
// but its value is zero!
decimal baseAmount = ((Money)postImage["baseamount"]).Value;
}
追加: 運用後の更新の事前および事後イメージには、basemount のゼロ以外の値が含まれています。