EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

KB486767: How to Identify and List Empty User Groups with a Python Script in MicroStrategy Workstation


Rainiero Leon

Support Engineer • MicroStrategy


The article presents a Python script and a systematic approach for identifying and listing the names and IDs of empty user groups in a specific MicroStrategy environment. By using the MicroStrategy Workstation, the script supports administrators in effectively managing user groups by identifying the empty ones, thus enabling more efficient group management.

Symptom

In the Strategy WorkStation, administrators may encounter difficulties in manually identifying empty user groups, a process that can be laborious and error-prone. This script serves to automate this process, enhancing accuracy and saving time.
 

Cause

The necessity for this script arises from the administrative burden of manually identifying empty user groups in the Strategy environment, which can be a time-consuming and error-prone task.
 

Solution

For the identification and listing of empty user groups, follow these structured steps in the Strategy WorkStation:
1. Connect to Your Environment: Initialize the connection to your Strategy environment.
2. Navigate to Administration: Access the administration panel to manage scripts and workflows.
3. Access Scripts Section: Go to the scripts section where you can create or modify scripts.
4. Select Your Environment: Choose the appropriate environment where the script will be executed.
5. Open Gallery Tab: In the right section of the interface, select the Gallery tab to view available workflows and scripts.
6. Expand Administration Workflows: Find and expand the Administration Workflows section to access various administrative scripts.
7. Launch 'List Empty User Groups' Script: Double-click on the 'list empty user groups' script to open it.
8. Execute the Script: Press the run button to execute the script, which will automatically list the names and IDs of empty user groups.

ka0PW0000002CGPYA2_0EMPW000006YoWp.jpeg

Here is the Python script in WorkStation that facilitates this operation:


"""List names and IDs of empty user groups."""

from typing import List

from mstrio.connection import Connection, get_connection
from mstrio.users_and_groups import list_user_groups, UserGroup

def list_empty_user_groups(connection: "Connection") -> List["UserGroup"]:
    """List empty user groups.

    Args:
        connection: Strategy connection object returned by
            `connection.Connection()`
    """
    all_user_groups = list_user_groups(connection=connection)
    return [user_group_ for user_group_ in all_user_groups if not user_group_.list_members()]

# connect to environment without providing user credentials
# variable `workstationData` is stored within Workstation
conn = get_connection(workstationData, 'Strategy Tutorial')

# get empty user groups
empty_user_groups = list_empty_user_groups(conn)

# print empty user groups
print('Empty user groups:', flush=True)
for ug in empty_user_groups:
    print(f"{ug.name} ({ug.id}) ", flush=True)

 

Related articles 

Python within Workstation https://www2.Strategy.com/producthelp/Current/Workstation/en-us/Content/intro_scripts.htm 
Preview Python Scripts https://www2.Strategy.com/producthelp/Current/Workstation/en-us/Content/preview_scripts.htm
mstrio-py https://github.com/MicroStrategy/mstrio-py 
https://www2.Strategy.com/producthelp/Current/Workstation/en-us/Content/intro_scripts.htm
Customization Warning:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.


Comment

0 comments

Details

Knowledge Article

Published:

June 7, 2024

Last Updated:

June 7, 2024