Sharing A Record with Different Business Unit Teams

Hello Everyone,

I was working on a requirement where i need to share records in different business unit teams. So i am sharing my knowledge how i achieve it using owner team.

First thing i am creating a security role in root business unit and give the right permission and access to entity “Account1”.

Create teams in those child BU where you want to share the records. I have created a Child BU as Bangalore. Create a teams in Child BU.

Assign the security role to Teams which you have created.(You will see Root BU security roles in every business unit because child BU Security roles inherit the parent roles.)

I have an entity name as “Account1” in which having a lookup of business unit. On record creation the record will be share to the respected team e.g. “Account1 Team”. To achieve this functionality i am going to right a custom workflow and calling it under OOB workflow.

Here is my custom code activity.

using System;
using System.Activities;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;

namespace shareAccount1
    public class shareAccount1: CodeActivity
        [Input("Send To")]
        public InArgument<EntityReference> sendTo { get; set; }

        protected override void Execute(CodeActivityContext context)
            ITracingService tracingService = (ITracingService)context.GetExtension<ITracingService>();
            IWorkflowContext workflowContext = (IWorkflowContext)context.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)context.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);
            var buname = this.sendTo.Get<EntityReference>(context);
            EntityReference UserRef = null;
            Entity targetEntity = (Entity)workflowContext.InputParameters["Target"];
            Guid CTIId = targetEntity.Id;
            string entityLogicalName = targetEntity.LogicalName;
            Guid businessunitlookupid = buname.Id;
            //Guid businessunitlookupid = ((EntityReference)targetEntity.Attributes["new_sendto"]).Id;

            QueryExpression queryExpression = new QueryExpression("team");
            queryExpression.ColumnSet.AddColumns("name", "teamid", "businessunitid");
            queryExpression.Criteria = new FilterExpression();
            queryExpression.Criteria.AddCondition("name", ConditionOperator.Equal, "Account1 Team");
            queryExpression.Criteria.AddCondition("businessunitid", ConditionOperator.Equal, businessunitlookupid);

            EntityCollection entityCollection = service.RetrieveMultiple(queryExpression);
            if (entityCollection.Entities.Count > 0)
                foreach (Entity teamEntity in entityCollection.Entities)

                    UserRef = new EntityReference(teamEntity.LogicalName, teamEntity.Id);
            var recordRef = new EntityReference(targetEntity.LogicalName, targetEntity.Id);

            // Principal – for whom we are sharing  the record.

            // Target – Which record we are sharing.

            //Sharing a RECORD
            GrantAccessRequest request = new GrantAccessRequest
                PrincipalAccess = new PrincipalAccess
                    AccessMask = AccessRights.ReadAccess|AccessRights.WriteAccess ,
                    Principal = UserRef
                Target = recordRef

            // throw new NotImplementedException();


Register your code activity using plugin registration tool. create a OOB workflow and select your workflow from the steps.

Set the property as below. As i earlier mentioned i have a lookup field on my form which is Send To, which i am setting in the input parameter of workflow.

Once it is done activate your workflow and test.I created a record new record “TestShare1” where owner of the record is Venkateshwararoa. Once it is created it will share the record to team member of different BU.

After creation , record is shared with Surya Singh as member of the Account1 Team.

That’s it. Shot comment on the blog if you facing any challenges.

Author: Surya Pratap Singh

I am a Dynamics 365 Sales Functional Consultant Associate|MCSE|MCSA|MCP.

One thought on “Sharing A Record with Different Business Unit Teams”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s