特定のユーザーを除くすべてのユーザーは、特定の条件を満たさない見積もりの詳細を編集または更新することはできませんが、必要に応じて見積もりを修正できる必要があります。
問題は、見積もりを修正すると (つまり、ユーザーがアクティブ フォーム レコードの [修正] ボタンをクリックすると)、見積もりの詳細が更新され、何が起こっているのかを認識する方法がわかりません。
私の現在の試みは、コードが次のようなプラグインに基づいています。
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
ありますか?
私が見落としている可能性のある情報については、お尋ねください。