Skip to main content

Notifications

Announcements

No record found.

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,457

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 

  • sandeepc Profile Picture
    5,457 on at
    RE: Business Unit ,Teams,Users

    Showing object reference null error

  • sandeepc Profile Picture
    5,457 on at
    RE: Business Unit ,Teams,Users

    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,457 on at
    RE: Business Unit ,Teams,Users

    Any other solution or steps pls .how to add syntax

  • sandeepc Profile Picture
    5,457 on at
    RE: Business Unit ,Teams,Users

    Any links or steps available

  • Verified answer
    Saad Kabarousse Profile Picture
    734 on at
    RE: Business Unit ,Teams,Users

    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.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans