web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Business Unit ,Teams,Users

(0) ShareShare
ReportReport
Posted on by 5,514

Hi, All 

I have a requirement to get 

How many Business Unit are there for that BU 

How many users and teams are there . 

What will be the advanced find search after downloaded how to add it in console app

Answers will be verified

Thanks 

I have the same question (0)
  • Verified answer
    Saad Kabarousse Profile Picture
    734 on at

    Hello,

    I guess you'll need 3 requests : One is global and two are embeded under teh first One,

    Request 1: the first will retrieve all BusinessUnits (BusinessUnitId , Name).

    (Loop Over the list of BusinessUnits):

    Request 2-1: For each Bu you'll look for its associated Teams Via the (BusinessUnitId) attribute on the team entity.

    Request 2-2 : For each Bu you'll look for its associated SystemUsers Via the (BusinessUnitId) attribute on the System User entity.

    and keep the counter turning :)

    This will do it my friend.

  • sandeepc Profile Picture
    5,514 on at

    Any links or steps available

  • sandeepc Profile Picture
    5,514 on at

    Any other solution or steps pls .how to add syntax

  • sandeepc Profile Picture
    5,514 on at

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using Microsoft.Xrm.Tooling.Connector;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Crm.Sdk.Messages;

    using Microsoft.Xrm.Sdk.Query;

    namespace ConsoleApp1

    {

       class Program

       {

           static void Main(string[] args)

           {

               try

               {

                   var connectionString = @"AuthType = Office365; Url = xyz/;Username=abc.onmicrosoft.com ;Password=xxx";

                   CrmServiceClient conn = new CrmServiceClient(connectionString);

                   IOrganizationService service;

                   service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

                   string fetchXmlCurrentUserbusinessunit = @" < fetch version = '1.0'

               output - format = 'xml-platform'

               mapping = 'logical'

               distinct = 'false' > < entity name = 'businessunit' > < attribute name = 'businessunitid' / > < filter type = 'and' > < condition attribute = 'isDisabled'

               operator = 'eq' / > < / filter > < / entity > < / fetch > ";

                   var businessunit = service.RetrieveMultiple(new FetchExpression(fetchXmlCurrentUserbusinessunit));

                   ColumnSet allFields = new ColumnSet() { AllColumns = true };

                   //Entity retrievedContact = service.Retrieve(contact.LogicalName, contactId, new ColumnSet(true));

                   //Console.WriteLine("Record retrieved {0}", retrievedContact.Id.ToString());

                  // Guid businessunitId = service.Retrieve(businessunit);

                  // Console.WriteLine("businessunit", businessunit.ToString());

                   // Entity businessunit = service.Retrieve("businessunit", businessunit, allFields);

                 //  retrievedBusinessunit = service.Retrieve(Businessunit.LogicalName, businessunitId, attributes);

                   foreach (var c in businessunit.Entities)

                   {

                       Console.WriteLine("retreived");

                   }

               }

               catch (Exception ex)

               {

                   Console.WriteLine(ex.Message);

                   Console.ReadLine();

               }

           }

       }

    }

  • sandeepc Profile Picture
    5,514 on at

    Showing object reference null error

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 128 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 95

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans