1

アカウントの所有者を設定し、同じ所有者のすべての子の連絡先を更新する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);
        }
    }

トレースサービスは、私が期待するすべてのものを印刷します。システムユーザーもアタッチし、エンティティ参照をコンテキストにアタッチする必要がありますか?

助けていただければ幸いです。

4

2 に答える 2

4

レコードの所有権を変更するには、AssignRequestを使用して別のWebサービス呼び出しを行う必要があります。残念ながら、Owner属性を変更することはできません。

于 2012-07-13T13:28:55.690 に答える
0

デフォルトでアカウント所有者を変更すると、関連付けられた連絡先の所有者が自動的に変更されるため、このプラグインであらゆる種類の混乱に陥っていたと思います。したがって、私はそれがすでに行っていた何かを上書きしようとしていました。

子レコードではなく、AssignRequestを使用してアカウント所有者を設定することにより、正常に機能しました。クリスが私を正しい方向に向けたときに与えられたクレジット。

必要なのは、AssignRequestを使用するようにコードの最初の行を変更することだけで、UpdateContactsメソッド全体が廃止されました。

于 2012-07-16T12:29:20.507 に答える