XrmMockup
XrmMockup copied to clipboard
Owning Business Unit not set on Target Entity during Create Post-Operation
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
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.