Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Owning Business Unit not set on Target Entity during Create Post-Operation #92

Open
bo-stig-christensen opened this issue Mar 3, 2020 · 1 comment

Comments

@bo-stig-christensen
Copy link
Member

Describe the bug
In a Create Post-Operation plugin on an entity with calling user as the owner, Target Entity does not have an 'owningbusinessunit' attribute defined in Mockup Tests. However, in D365 this attribute is present in Target Entity in Post-Operation stage.
Assuming same issue with a team as owner regarding 'owningteam' attribute.

No workaround possible, even setting the raw attribute becomes null in Mockup Test.

To Reproduce

[TestMethod]
public void GivenUserInBusinessUnit_WhenCreatingAccount_ExpectOwnerToBeBusinessUnit()
{
    // Arrange
    var userDenmark = new SystemUser
    {
        FirstName = "Luke",
        LastName = "Skywalker",
        InternalEMailAddress = "[email protected]",
        BusinessUnitId = _businessUnitDenmark.ToEntityReference()
    };
    userDenmark = Crm.CreateUser(OrgAdminService, userDenmark, SecurityRoles.Salesperson) as SystemUser;
    OrgService = Crm.CreateOrganizationService(userDenmark.Id);

    // Act
    var account = new Account
    {
        Name = "Test Account"
    };
    account.Id = OrgService.Create(account);

    // Assert
    var accountFromD365 = Account.Retrieve(OrgAdminService, account.Id);
    accountFromD365.OwnerId.Id.Should().Be(_businessUnitDenmark.Id);
}

A plugin is in place that contains this fragment:

using (var context = new Xrm(localContext.OrganizationAdminService))
{
    var owningBusinessUnitTeam = context.TeamSet.FirstOrDefault(x => x.BusinessUnitId.Id == targetEntity.OwningBusinessUnit.Id);
    if (owningBusinessUnitTeam != null)
        localContext.OrganizationAdminService.Update(new Account(targetEntity.Id) { OwnerId = owningBusinessUnitTeam.ToEntityReference() });

The usage of OwningBusinessUnit.Id throws an exception in Mockup, but not in D365.

Expected behavior
OwningBusinessUnit should be populated in Create Post-Operation as it is in D365.

Environment

  • CRM/D365/CDS version: 9.1.x
  • Tool version: 1.1.0
@MattTrinder1
Copy link
Contributor

MattTrinder1 commented Aug 13, 2020

This looks to be related to #101 where other system field values are not set in the post operation plugin - it should be possible to add OwningBusinessUnit into the list of system attributes so that it is included.

#104 contains the work to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants