web
You’re offline. This is a read only version of the page.
close
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,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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 73 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans