アカウントの所有者を設定し、同じ所有者のすべての子の連絡先を更新するCRM2011のプレイベントプラグインを作成しています。プラグインは正しくインストールされ、メインアカウントレコードを正しく更新しますが、子の連絡先の所有者は変更されません。連絡先の別のフィールドに所有者名をプッシュして、正しい詳細があり、そのフィールドが更新されていることを確認しました。
子の連絡先を正しいコンテキストにアタッチすることと関係があると確信していますが、これまでのところ空白を描画しています。
//Set new account owner - Works fine
account.OwnerId = new EntityReference(SystemUser.EntityLogicalName, ownerId);
//Pass the same owner into the contacts - Does not get updated
UpdateContacts(account.Id, ownerId, service, tracingService);
システムは、アカウント所有者と子レコードの説明ラベルを正常に更新しています。
public static void UpdateContacts(Guid parentCustomerId, Guid ownerId, IOrganizationService service, ITracingService tracingService)
{
// Create the FilterExpression.
FilterExpression filter = new FilterExpression();
// Set the properties of the filter.
filter.FilterOperator = LogicalOperator.And;
filter.AddCondition(new ConditionExpression("parentcustomerid", ConditionOperator.Equal, parentCustomerId));
// Create the QueryExpression object.
QueryExpression query = new QueryExpression();
// Set the properties of the QueryExpression object.
query.EntityName = Contact.EntityLogicalName;
query.ColumnSet = new ColumnSet(true);
query.Criteria = filter;
// Retrieve the contacts.
EntityCollection results = service.RetrieveMultiple(query);
tracingService.Trace("Results : " + results.Entities.Count);
SystemUser systemUser = (SystemUser)service.Retrieve(SystemUser.EntityLogicalName, ownerId, new ColumnSet(true));
tracingService.Trace("System User : " + systemUser.FullName);
XrmServiceContext xrmServiceContext = new XrmServiceContext(service);
for (int i = 0; i < results.Entities.Count; i++)
{
Contact contact = (Contact)results.Entities[i];
contact.OwnerId = new EntityReference(SystemUser.EntityLogicalName, systemUser.Id);
contact.Description = systemUser.FullName;
xrmServiceContext.Attach(contact);
xrmServiceContext.UpdateObject(contact);
xrmServiceContext.SaveChanges();
tracingService.Trace("Updating : " + contact.FullName);
}
}
トレースサービスは、私が期待するすべてのものを印刷します。システムユーザーもアタッチし、エンティティ参照をコンテキストにアタッチする必要がありますか?
助けていただければ幸いです。