1
私は開発にかなり新しいですが、Dynamics CRMのプラグインを作成する際に問題が発生しました。プラグインは、primarycontactidフィールドが別のものに更新されたときに、それがリンクされているアカウントエンティティが更新されたときにcontactエンティティにparentcustomeridフィールドをnullにすることになっています。CRMプラグインPreImage関連エンティティを更新していません
私は現在書いたコードではエラーはスローされず、コードは正常に実行されますが、parentcustomeridフィールドにはリンクを削除する必要があるときにリンクされているアカウントも含まれています。誰もが私のために、この問題を解決することができれば、それは素晴らしいのおかげだろう
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
//Obtain the execution context
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
//obtain organizational services
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
EntityReference prePCID;
Entity PreImage;
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the image entity from the Pre Entity Images.
tracingService.Trace
("trace1: Getting the target entity from Input Parameters.");
PreImage = (Entity)context.InputParameters["Target"];
// Verify that the target entity represents an account.
// If not, this plug-in was not registered correctly.
tracingService.Trace
("trace2: Verifying that the target entity represents a account.");
if (PreImage.LogicalName == "account")
{
if (PreImage.Attributes.Contains("primarycontactid"))
{
tracingService.Trace
("trace3: Setting the primary contact id in the prePCID.");
//prePCID = (EntityReference)PreImage.Attributes["primarycontactid"];
prePCID = (EntityReference)PreImage["primarycontactid"];
tracingService.Trace
("trace4: Primary Contact Name: " + prePCID.Name + " Creating a variable that stores the contact using the prePCID.");
Entity contactToRemoveReference = service.Retrieve("contact", prePCID.Id, new ColumnSet("parentcustomerid")) as Entity;
tracingService.Trace
("trace5: Removes the id: " + prePCID.Id + " of the parentcustomerid.");
contactToRemoveReference.Attributes["parentcustomerid"] = null;
service.Update(contactToRemoveReference);
tracingService.Trace
("trace6: Execution Successful.");
}
}
}
}
:ここ
は私が現在持っているコードです。
プラグインはどのように登録されていますか? –
メッセージは更新で、プライマリエンティティはアカウントです。私がステップを登録したとき、プリオペレーション –
に設定されました。プリイメージは、ステップ –