Recently, I had to create a plugin that gets all the child Business Units of an specific Business Unit. As this can be a simple task for developers with experience in the customization of the platform, it can also be difficult to new developers. Hence, I wanted to share how I did it in case someone need it.
// Create XRM Service Context(Sending the IOrganization service as parameter) XrmServiceContext XRM_Context = new XrmServiceContext(service); // Parent Business Unit EntityReference Parent_BusinessUnit = context.InputParameters["owningbusinessunit"] as EntityReference; // LINQ query to get all child Business Units List<Guid> Child_BusinessUnits = (from BusinessUnitEntity in XRM_Context.BusinessUnitSet where BusinessUnitEntity.ParentBusinessUnitId.Id.Equals(Parent_BusinessUnit.Id) select BusinessUnitEntity.Id).ToList(); /* * Your logic with the list of child Business Units */
Hope it helps!