0

特定のユーザーを除くすべてのユーザーは、特定の条件を満たさない見積もりの​​詳細を編集または更新することはできませんが、必要に応じて見積もりを修正できる必要があります。

問題は、見積もりを修正すると (つまり、ユーザーがアクティブ フォーム レコードの [修正] ボタンをクリックすると)、見積もりの​​詳細が更新され、何が起こっているのかを認識する方法がわかりません。

私の現在の試みは、コードが次のようなプラグインに基づいています。

public class PreQuoteProductUpdate : Plugin
{
// I work with CRM Developer Tools to build plugins 
// This goes in Update Message, Pre-Operation, Server Only, pre-image called "preImage"

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

    IPluginExecutionContext context = localContext.PluginExecutionContext;
    IOrganizationService srv = localContext.OrganizationService;

    Entity preImageEntity = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null;

    try
    {
        PluginBody(context, srv, preImageEntity);
    }
    catch (Exception ex)
    {
        throw new InvalidPluginExecutionException("Quote Details Pre-Update", ex);
    }
}

protected void PluginBody(IPluginExecutionContext context, IOrganizationService srv, Entity preImage)
{
    if(IsRevising()) return;

    CheckSomeCondition(context, srv);

    if (preImage.Attributes.ContainsKey("ica_daconfigurazione") && preImage.GetAttributeValue<bool>("ica_daconfigurazione"))
    {
        CheckUser(context, srv);
    }
}

protected void IsRevising()
{
    // I have no clue about the logic to put here: see below.
}

protected void CheckSomeCondition(IPluginExecutionContext context, IOrganizationService srv)
{
    var entity = (Entity)context.InputParameters["Target"];
    // if some fields of entity contain some specific data, throw
    // this always happens
}

protected void CheckUser(IPluginExecutionContext context, IOrganizationService srv)
{
    //allowedUser is read from a configuration entity
    var allowedUser = new Guid();
    if (context.InitiatingUserId.Equals(serviceUser.Id) == false)
        throw new InvalidPluginExecutionException("Can't edit quote details");
}

}

(Quoteプラグインで) をチェックすることで改訂が進行中であることを知ることができます。プラグインParentContextで同様のものを利用できQuoteDetailますか? 私はそれを試してみましたが、私が得たNullReferenceExceptionのは私に投げられたものだけです。

State/をチェックできるようにする必要がStatusありますか?

私が見落としている可能性のある情報については、お尋ねください。

4

1 に答える 1

1

Pre Createのメッセージ (ステージ 20) に登録し、QuoteDetail対象外の親コンテキストでフィルター処理しますQuote。そうである場合は、単に戻ります (事実上何もしません)。Updateのメッセージも同様QuoteDetailです。どちらのメッセージも、 のメッセージ
のコンテキストで実行されます。ReviseQuoteQuote

var parentContext = context.ParentContext;

// While there is a parent context...
while (parentContext != null) {
    // When parent context is for "quote", return;
    if (parentContext.PrimaryEntityName == "quote")
    {
        return;
    }
    // Assign parent's parent context to loop parent context.
    parentContext = parentContext.ParentContext;
}
于 2013-09-06T11:17:21.937 に答える