Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Business Unit ,Teams,Users

Posted on by 5,005

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

    Showing object reference null error

  • sandeepc Profile Picture
    sandeepc 5,005 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
    sandeepc 5,005 on at
    RE: Business Unit ,Teams,Users

    Any other solution or steps pls .how to add syntax

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

    Any links or steps available

  • Verified answer
    Saad Kabarousse Profile Picture
    Saad Kabarousse 732 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans