Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member203619
Contributor

When administering an Enterprise system, a common task is to apply some kind of change to all the users on the system.  The scripts I have included below are ones that I have created to handle various tasks and work around other issues which can't be easily fixed through the CMC or Infoview.

Warning

The code given below can be very destructive if not used properly.  Please ensure that you have made a backup of your CMS database and your Input and Output FRS prior to running any code.

Most of the scripts are based off the scripting template found here: http://scn.sap.com/docs/DOC-38620

For other scripts and information on how to run these scripts see here:

shawn.penner/blog/2013/06/04/scripts-and-samples

Enable or Disable All Users

This first script can be used to enable or disable all users on the system.  It excludes the Administrator and Guest accounts as those are special accounts that aren't generally touched.

Notes:

•You can toggle the disableUsers variable to true or false depending on if you want to enable or disable all users (True = disable, False = Enable)
•You will need to change the username, password, and CMS name to the values specific to your enterprise server.

Enable or Disable All Users

<%@ page import = "com.crystaldecisions.sdk.exception.SDKException,
com.crystaldecisions.sdk.framework.*,
com.crystaldecisions.sdk.occa.infostore.*,
com.crystaldecisions.sdk.occa.report.*,
com.crystaldecisions.sdk.properties.*,
com.crystaldecisions.sdk.plugin.desktop.user.*,
java.util.*"
%>

<%
// User Credentials
String username = "Administrator";
String password = "MyPassword";
String cmsname  = "MyEnterpriseServer";
String authType = "secEnterprise";

// Set to true to disable all users, false to enable all users
Boolean disableUsers = true;

IEnterpriseSession enterpriseSession = null;
IInfoStore infoStore;
IInfoObjects boInfoObjects;

// Log onto Enterprise
enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
infoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

// The SI_ID to start at when searching
int max_id = 0;

for(;;) {

// Loop through all users - excluding Administrator and Guest
boInfoObjects = (IInfoObjects)infoStore.query("Select * FROM CI_SYSTEMOBJECTS WHERE SI_Kind='User' AND SI_NAME!= 'Administrator' and SI_NAME !='Guest' AND SI_ID > " + max_id + " ORDER BY SI_ID ASC");

// If there are no more objects then we're done.
if(boInfoObjects.size() == 0)
break;

for(Iterator boCount = boInfoObjects.iterator() ; boCount.hasNext() ; ) {
  IInfoObject boObject = (IInfoObject)boCount.next();

  IUser boUser = (IUser)boObject;
  Iterator boIterator = boUser.getAliases().iterator();
  while(boIterator.hasNext())
  {
   IUserAlias boAlias = (IUserAlias)boIterator.next();
   out.println("current status is: " + boAlias.isDisabled());
   boAlias.setDisabled(disableUsers);
  
   if (disableUsers) {
    out.println("user name: " + boAlias.getName() + " has been disabled<BR>");
   } else {
    out.println("user name: " + boAlias.getName() + " has been enabled<BR>");
   }
  }
   max_id = boObject.getID();
}
infoStore.commit(boInfoObjects);
}
out.println("Completed</br>");

%>

Enable or Disable UserGroup

This second script is a variation of the first one, except it allows you to specify what group of users you want to enable or disable.  It checks for the Administrator and Guest accounts as well and doesn't touch them.

Notes:

•You can toggle the disableUsers variable to true or false depending on if you want to enable or disable all users for the specified group (True = disable, False = Enable)
•You will need to change the groupName variable to your desired group (Or use "Everyone" for all users)
•You will need to change the username, password, and CMS name to the values specific to your enterprise server.

Enable or Disable UserGroup

<%@ page import = "com.crystaldecisions.sdk.exception.SDKException,
com.crystaldecisions.sdk.framework.*,
com.crystaldecisions.sdk.occa.infostore.*,
com.crystaldecisions.sdk.occa.report.*,
com.crystaldecisions.sdk.properties.*,
com.crystaldecisions.sdk.plugin.desktop.user.*,
com.crystaldecisions.sdk.plugin.desktop.usergroup.*,
java.util.*"
%>

<%
// User Credentials
String username = "Administrator";
String password = "MyPassword";
String cmsname  = "MyEnterpriseServer";
String authType = "secEnterprise";

// Set to true to disable all users, false to enable all users
Boolean disableUsers = true;
String groupName = "test1";

IEnterpriseSession enterpriseSession = null;
IInfoStore infoStore;
IInfoObjects boInfoObjects;

// Log onto Enterprise
enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
infoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

// Retrieve the specified group
boInfoObjects = (IInfoObjects)infoStore.query("Select * FROM CI_SYSTEMOBJECTS WHERE SI_PROGID='CrystalEnterprise.UserGroup' and SI_NAME = '" + groupName + "'");

// If no groups found with that name - then exit
if(boInfoObjects.size() == 0)
{
out.println("No groups found with name " + groupName);
} else {

IUserGroup currentGroup = (IUserGroup)boInfoObjects.get(0);

//retrieve the Set object and it's Iterator
    Set boUserList = currentGroup.getUsers();
Iterator boUserIterator = boUserList.iterator();
   
// This set contains the SI_ID's of the users that belong to the group
while(boUserIterator.hasNext())
{
  IInfoObjects boInfoObjects2 = (IInfoObjects)infoStore.query("Select * FROM CI_SYSTEMOBJECTS WHERE SI_ID = " + boUserIterator.next());
  IUser boUser = (IUser)boInfoObjects2.get(0);
 
  // Don't touch the Administrator or Guest user accounts
  if (!boUser.getTitle().equals("Administrator") && !boUser.getTitle().equals("Guest"))
  {
 
   Iterator boIterator = boUser.getAliases().iterator();
   while(boIterator.hasNext())
   {
    IUserAlias boAlias = (IUserAlias)boIterator.next();
    boAlias.setDisabled(disableUsers);
  
    if (disableUsers) {
     out.println("user name: " + boAlias.getName() + " has been disabled<BR>");
    } else {
     out.println("user name: " + boAlias.getName() + " has been enabled<BR>");
    }
   }
  }
  infoStore.commit(boInfoObjects2);
}
}
out.println("Completed</br>");

%>

Count Reports and Instances

This next script was created to count determine how many reports and how many instances are owned by each user on an Enterprise system.  This script loops through all reports and instances on the system, and outputs the count for each user to the CSV file C:\TestOutput.csv.

Notes:

•You can change the location and filename of the log file as needed - just change the line "FSout = new FileOutputStream("C:\\TestOutput.csv", true);"
•You will need to change the username, password, and CMS name to the values specific to your enterprise server.

Count Reports and Instances

<%@ page import = "com.crystaldecisions.sdk.exception.SDKException,
com.crystaldecisions.sdk.framework.*,
com.crystaldecisions.sdk.occa.infostore.*,
com.crystaldecisions.sdk.occa.report.*,
com.crystaldecisions.sdk.properties.*,
com.crystaldecisions.sdk.plugin.desktop.user.*,
java.util.*,
java.io.*"
%>

<%
// User Credentials
String username = "Administrator";
String password = "MyPassword";
String cmsname  = "MyEnterpriseServer";
String authType = "secEnterprise";

IEnterpriseSession enterpriseSession = null;
IInfoStore infoStore;
IInfoObjects boInfoObjects;

// Log onto Enterprise
enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
infoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

// The SI_ID to start at when searching
int max_id = 0;

writeToLog("UserID,UserName,ReportsOwned,ReportInstancesOwned");

for(;;) {

// Loop through all users
boInfoObjects = (IInfoObjects)infoStore.query("Select * FROM CI_SYSTEMOBJECTS WHERE SI_Kind='User' AND SI_ID > " + max_id + " ORDER BY SI_ID ASC");

// If there are no more objects then we're done.
if(boInfoObjects.size() == 0)
break;

// Loop through all users
for(Iterator boCount = boInfoObjects.iterator() ; boCount.hasNext() ; ) {
  IInfoObject boObject = (IInfoObject)boCount.next();

  int max_id2 = 0;
  int max_id3 = 0;
  int countReports = 0;
  int countInstances = 0;
 
  // Now loop through all report templates and count how many the user owns
  for(;;) {
   IInfoObjects boInfoObjects2 = (IInfoObjects)infoStore.query("Select * FROM CI_INFOOBJECTS WHERE SI_OWNERID = " + boObject.getID() + " AND SI_INSTANCE=0 AND SI_ID > " + max_id2 + " AND (SI_KIND='CrystalReport' OR SI_KIND='Webi' OR SI_KIND = 'FullClient') ORDER BY SI_ID ASC");
  
   // If there are no more objects then we're done.
   if(boInfoObjects2.size() == 0)
   break;
  
   countReports+=countReports + boInfoObjects2.size();
   max_id2 = ((IInfoObject)boInfoObjects2.get(boInfoObjects2.size()-1)).getID();
  }

  // Now loop through all report instances and count how many the user owns
  for(;;) {
   IInfoObjects boInfoObjects3 = (IInfoObjects)infoStore.query("Select * FROM CI_INFOOBJECTS WHERE SI_OWNERID = " + boObject.getID() + " AND SI_INSTANCE=1 AND SI_ID > " + max_id3 + " ORDER BY SI_ID ASC");
  
   // If there are no more objects then we're done.
   if(boInfoObjects3.size() == 0)
   break;
  
   countInstances+=countInstances + boInfoObjects3.size();
   max_id3 = ((IInfoObject)boInfoObjects3.get(boInfoObjects3.size()-1)).getID();
  }

  writeToLog(boObject.getID() + "," + boObject.getTitle() + "," + countReports + "," + countInstances);
   max_id = boObject.getID();
}

}
out.println("Completed</br>");

%>

<%!

public void writeToLog(String msg) {
try {
  // Set up Logging File
  FileOutputStream FSout;
  PrintStream pStream; // declare a print stream object
  FSout = new FileOutputStream("C:\\TestOutput.csv", true);  // Append
  pStream = new PrintStream(FSout);
  pStream.println(msg);
  pStream.close();
} catch (IOException e) {
  //error writing to log
    }
}
%>

Change Owner

This script was designed to take all Crystal Reports owned by one user, and change them to be owned by a different user.  It sets the SI_OWNERID property of the reports which is then automatically propagated to the SI_OWNER property (Which is read only).

Notes:

•You will need to change the username, password, and CMS name to the values specific to your enterprise server.
•You will need to change the sourceUserID and destUserID variables to the SI_ID's of the users you want to change ownership

Change Owner

<%@ page import = "com.crystaldecisions.sdk.exception.SDKException,
com.crystaldecisions.sdk.framework.*,
com.crystaldecisions.sdk.occa.infostore.*,
com.crystaldecisions.sdk.occa.report.*,
com.crystaldecisions.sdk.properties.*,
java.util.*"
%>

<%
// User Credentials
String username = "Administrator";
String password = "MyPassword";
String cmsname  = "MyEnterpriseServer";
String authType = "secEnterprise";

String sourceUserID = "12345";     // SI_ID of source user (current owner)
String destUserID = "67890";  // SI_ID of target user

IEnterpriseSession enterpriseSession = null;
IInfoStore infoStore;
IInfoObjects boInfoObjects;

// Log onto Enterprise
enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
infoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

// The SI_ID to start at when searching
int max_id = 0;

for(;;) {

// Loop through all objects
boInfoObjects = (IInfoObjects)infoStore.query("Select SI_ID, SI_OWNER, SI_OWNERID FROM CI_INFOOBJECTS WHERE SI_OWNERID = " + sourceUserID + " AND SI_PROGID = 'CrystalEnterprise.Report' AND SI_ID > " + max_id + " ORDER BY SI_ID ASC");

// If there are no more objects then we're done.
if(boInfoObjects.size() == 0)
break;

for(Iterator boCount = boInfoObjects.iterator() ; boCount.hasNext() ; ) {
IInfoObject boObject = (IInfoObject)boCount.next();

// If you don't cast it as an integer - the code will not throw any error messages, but it also will not do anything.
boObject.properties().setProperty("SI_OWNERID", Integer.parseInt(destUserID));

out.println("Changed owner for report ID " + boObject.getID() + " with title " + boObject.getTitle() + "</br>");
max_id = boObject.getID();
}
infoStore.commit(boInfoObjects);
}
out.println("Completed</br>");

%>

Copy User Preferences Globally

This script was designed to take the preferences from a single user and copy it out to a specified group.  It automatically excludes the Administrator and Guest accounts if they happen to be present in the group specified (e.g. The "Everyone" group).  To use this script, set up one user the way you want all users configured, then set the sourceUserID and groupName variables and run the script.

Notes:

•You will need to change the username, password, and CMS name to the values specific to your enterprise server.
•You will need to change the sourceUserID variable to the SI_ID of the source user, and the groupName variable to the name of the group you want to change.

Copy User Preferences Globally

<%@ page import = "com.crystaldecisions.sdk.exception.SDKException,
com.crystaldecisions.sdk.framework.*,
com.crystaldecisions.sdk.occa.infostore.*,
com.crystaldecisions.sdk.occa.report.*,
com.crystaldecisions.sdk.properties.*,
com.crystaldecisions.sdk.plugin.desktop.user.*,
com.crystaldecisions.sdk.plugin.desktop.usergroup.*,
java.util.*"
%>

<%
// User Credentials
String username = "Administrator";
String password = "MyPassword";
String cmsname  = "MyEnterpriseServer";
String authType = "secEnterprise";

String sourceUserID = "12345";
String groupName = "testGroup";

IEnterpriseSession enterpriseSession = null;
IInfoStore infoStore;
IInfoObjects boInfoObjects;
IInfoObjects boInfoObjects3;

// Log onto Enterprise
enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
infoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

// Retrieve the specified group
boInfoObjects = (IInfoObjects)infoStore.query("Select * FROM CI_SYSTEMOBJECTS WHERE SI_PROGID='CrystalEnterprise.UserGroup' and SI_NAME = '" + groupName + "'");

// Retrieve the source User
boInfoObjects3 = (IInfoObjects)infoStore.query("SELECT SI_NAME, SI_DATA FROM CI_SYSTEMOBJECTS WHERE SI_PROGID = 'CrystalEnterprise.User' And SI_ID = " + sourceUserID + " And SI_DATA != NULL");

// If no groups found with that name - then exit
if(boInfoObjects.size() == 0 || boInfoObjects3.size() == 0)
{
if (boInfoObjects.size() == 0) {
  out.println("No groups found with name " + groupName);
} else {
  out.println("No user found or use" + sourceUserID + " had null preferences section");
}
} else {

IUserGroup currentGroup = (IUserGroup)boInfoObjects.get(0);
IUser sourceUser  = (IUser)boInfoObjects3.get(0);

// Get the source users SI_DATA entry
IProperties sourceProp = (IProperties)sourceUser.properties().getProperty("SI_DATA").getValue();

//retrieve the Set object and it's Iterator
Set boUserList = currentGroup.getUsers();
Iterator boUserIterator = boUserList.iterator();
   
// This set contains the SI_ID's of the users that belong to the group
while(boUserIterator.hasNext())
{
  IInfoObjects boInfoObjects2 = (IInfoObjects)infoStore.query("Select * FROM CI_SYSTEMOBJECTS WHERE SI_ID = " + boUserIterator.next());
  IUser boUser = (IUser)boInfoObjects2.get(0);
 
  // Don't touch the Administrator or Guest user accounts or the source User if they are part of the group
  if (!(boUser.getTitle().equals("Administrator") || boUser.getTitle().equals("Guest") || boUser.getTitle().equals( sourceUserName)))
  {
   IProperties targetProp = (IProperties)boUser.properties();
  
   // If the target user has no SI_DATA existing - then add it.  Both lines do the same thing - but it can be useful to know
   // if any preferences are being overwritten
   if (targetProp.getProperty("SI_DATA") == null) {
    out.println("User " + boUser.getTitle() + " had no preferences set - assigning new preferences. </br>");
    targetProp.add("SI_DATA", sourceProp,0);
   } else {
    out.println("User " + boUser.getTitle() + " had some preferences set - overwriting preferences. </br>");
    targetProp.add("SI_DATA", sourceProp,0);
   }
  }
  infoStore.commit(boInfoObjects2);
}
}
out.println("Completed</br>");

%>

Force Log Off

This script was designed to forcibly log off all users on a system.  It assumes that there are less than 1000 users currently logged onto the system (Since a query will only return 1000 records) - however if you have more users than 1000 logged in, you can re-run the script multiple times to remove everyone.  It sorts the query by SI_CREATION_TIME in order to ensure that the session used by the script is the last one removed.

Notes:

•You will need to change the username, password, and CMS name to the values specific to your enterprise server.

Force Log Off

<%@ page import = "com.crystaldecisions.sdk.exception.SDKException,
com.crystaldecisions.sdk.framework.*,
com.crystaldecisions.sdk.occa.infostore.*,
com.crystaldecisions.sdk.occa.report.*,
com.crystaldecisions.sdk.properties.*,
java.util.*"
%>

<%
// User Credentials
String username = "Administrator";
String password = "MyPassword";
String cmsname  = "MyEnterpriseServer";
String authType = "secEnterprise";

IEnterpriseSession enterpriseSession = null;
IInfoStore infoStore;
IInfoObjects boInfoObjects;

// Log onto Enterprise
enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
infoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

// Loop through all objects
boInfoObjects = (IInfoObjects)infoStore.query("SELECT SI_ID, SI_CREATION_TIME, SI_NAME FROM CI_SYSTEMOBJECTS WHERE SI_KIND = 'Connection' AND SI_FAILOVER_AVAILABLE_UNTIL = NULL AND SI_AUTHEN_METHOD != 'server-token' ORDER BY SI_CREATION_TIME ASC");

for(Iterator boCount = boInfoObjects.iterator() ; boCount.hasNext() ; ) {
IInfoObject boObject = (IInfoObject)boCount.next();

out.println("Removing Session for User " + boObject.getTitle() + "</br>");
boInfoObjects.delete(boObject);

}
infoStore.commit(boInfoObjects);
out.println("Completed</br>");

%>

Remove Aliases

This script was created to remove all aliases of a particular type from all users.  Just change the type of alias compared against to remove that type of alias.  The Administrator and Guest accounts are excluded from the script.

Notes:

•You will need to change the username, password, and CMS name to the values specific to your enterprise server.

Remove Aliases

<%@ page import = "com.crystaldecisions.sdk.exception.SDKException,
com.crystaldecisions.sdk.framework.*,
com.crystaldecisions.sdk.occa.infostore.*,
com.crystaldecisions.sdk.occa.report.*,
com.crystaldecisions.sdk.properties.*,
com.crystaldecisions.sdk.plugin.desktop.user.*,
java.util.*"
%>

<%
// User Credentials
String username = "Administrator";
String password = "MyPassword";
String cmsname  = "MyEnterpriseServer";
String authType = "secEnterprise";

IEnterpriseSession enterpriseSession = null;
IInfoStore infoStore;
IInfoObjects boInfoObjects;

// Log onto Enterprise
enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
infoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

// The SI_ID to start at when searching
int max_id = 0;

for(;;) {

// Loop through all users - excluding Administrator and Guest
boInfoObjects = (IInfoObjects)infoStore.query("Select * FROM CI_SYSTEMOBJECTS WHERE SI_Kind='User' AND SI_NAME!= 'Administrator' and SI_NAME !='Guest' AND SI_ID > " + max_id + " ORDER BY SI_ID ASC");

// If there are no more objects then we're done.
if(boInfoObjects.size() == 0)
break;

for(Iterator boCount = boInfoObjects.iterator() ; boCount.hasNext() ; ) {
  IInfoObject boObject = (IInfoObject)boCount.next();

  IUser boUser = (IUser)boObject;
  Iterator boIterator = boUser.getAliases().iterator();
  while(boIterator.hasNext())
  {
   IUserAlias boAlias = (IUserAlias)boIterator.next();
   String authentication = boAlias.getAuthentication();
  
   // If this alias is a secLDAP alias then remove it
   // Possible types of aliases are "secWinAD", "secEnterprise", "secWindowsNT", "secLDAP"
   if("secLDAP".equals(authentication)) {
    boUser.getAliases().remove(boAlias);
   }
  }
   max_id = boObject.getID();
}
infoStore.commit(boInfoObjects);
}
out.println("Completed</br>");

%>

Change Users to Named or Concurrent

This script was created to change all the users in a particular usergroup to either concurrent or named.  The Administrator and Guest user accounts are automatically excluded.

Notes:

•You will need to change the username, password, and CMS name to the values specific to your enterprise server.
•You will also want to change the groupName variable to the userGroup containing the users you want to modify.  The default is the everyone group

Change Users to Named or Concurrent

<%@ page import = "com.crystaldecisions.sdk.exception.SDKException,
com.crystaldecisions.sdk.framework.*,
com.crystaldecisions.sdk.occa.infostore.*,
com.crystaldecisions.sdk.occa.report.*,
com.crystaldecisions.sdk.properties.*,
com.crystaldecisions.sdk.plugin.desktop.user.*,
com.crystaldecisions.sdk.plugin.desktop.usergroup.*,
java.util.*"
%>

<%
// User Credentials
String username = "Administrator";
String password = "MyPassword";
String cmsname  = "MyEnterpriseServer";
String authType = "secEnterprise";

int boConnectionType = 1; // Set to 1 for conncurrent, 0 for named
String groupName = "Everyone";

IEnterpriseSession enterpriseSession = null;
IInfoStore infoStore;
IInfoObjects boInfoObjects;
IInfoObjects boInfoObjects3;

// Log onto Enterprise
enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
infoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

// Retrieve the specified group
boInfoObjects = (IInfoObjects)infoStore.query("Select * FROM CI_SYSTEMOBJECTS WHERE SI_PROGID='CrystalEnterprise.UserGroup' and SI_NAME = '" + groupName + "'");

// If no groups found with that name - then exit
if(boInfoObjects.size() == 0)
{
out.println("No groups found with name " + groupName + "</br>");
} else {

IUserGroup currentGroup = (IUserGroup)boInfoObjects.get(0);

//retrieve the Set object and it's Iterator
    Set boUserList = currentGroup.getUsers();
Iterator boUserIterator = boUserList.iterator();
   
// This set contains the SI_ID's of the users that belong to the group
while(boUserIterator.hasNext())
{
  IInfoObjects boInfoObjects2 = (IInfoObjects)infoStore.query("Select * FROM CI_SYSTEMOBJECTS WHERE SI_ID = " + boUserIterator.next());
  IUser boUser = (IUser)boInfoObjects2.get(0);
 
  // Don't touch the Administrator or Guest user accounts if they are part of the group
  if (!(boUser.getTitle().equals("Administrator") || boUser.getTitle().equals("Guest")))
  {
   boUser.setConnection(boConnectionType);
  
   if (boConnectionType == 1) {
    out.println("Set " + boUser.getTitle() + " user account to Concurrent </br>");
   } else {
    out.println("Set " + boUser.getTitle() + " user account to Named </br>");
   }
  
  }
  infoStore.commit(boInfoObjects2);
}
}
out.println("Completed</br>");

%>

Add Aliases

This script was designed to add aliases of a specific kind to all users who belong to a specific group (default is the everyone group).  It automatically excludes the Administrator and Guest accounts if they happen to be present in the group specified (e.g. The "Everyone" group)

Notes:

•You will need to change the username, password, and CMS name to the values specific to your enterprise server.
•You will also want to change the groupName variable to the userGroup containing the users you want to modify.  The default is the everyone group
•The isDisabled variable controls if the aliases are enabled when added.  Set to false to enable the aliases,  and true to disable them
•You can choose what Alias type you want by specifying the AliasType variable.  Be aware that this is case sensitive.  The possible options are secEnterprise, secLDAP, secWinAD, secWindowsNT
•You can find a .NET version of the alias adding code in kbase 1452123 - which can be found here: https://service.sap.com/sap/support/notes/1452123

Add Aliases

<%@ page import = "com.crystaldecisions.sdk.exception.SDKException,
com.crystaldecisions.sdk.framework.*,
com.crystaldecisions.sdk.occa.infostore.*,
com.crystaldecisions.sdk.occa.report.*,
com.crystaldecisions.sdk.properties.*,
com.crystaldecisions.sdk.plugin.desktop.user.*,
com.crystaldecisions.sdk.plugin.desktop.usergroup.*,
java.util.*"
%>
<%
// User Credentials
String username = "Administrator";
String password = "MyPassword";
String cmsname  = "MyEnterpriseServer";
String authType = "secEnterprise";

String groupName = "Everyone";  // Name of group to apply changes to
boolean isDisabled = false;   // Set to false if you want the aliases enabled as soon as they are added.
String AliasType = "secWinAD";  // Possible options are secEnterprise, secLDAP, secWinAD, secWindowsNT

IEnterpriseSession enterpriseSession = null;
IInfoStore infoStore;
IInfoObjects boInfoObjects;
IInfoObjects boInfoObjects3;

// Log onto Enterprise
enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
infoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

// Retrieve the specified group
boInfoObjects = (IInfoObjects)infoStore.query("Select * FROM CI_SYSTEMOBJECTS WHERE SI_PROGID='CrystalEnterprise.UserGroup' and SI_NAME = '" + groupName + "'");

// If no groups found with that name - then exit
if(boInfoObjects.size() == 0)
{
out.println("No groups found with name " + groupName + "</br>");
} else {

IUserGroup currentGroup = (IUserGroup)boInfoObjects.get(0);

//retrieve the Set object and it's Iterator
    Set boUserList = currentGroup.getUsers();
Iterator boUserIterator = boUserList.iterator();
   
// This set contains the SI_ID's of the users that belong to the group
while(boUserIterator.hasNext())
{
  IInfoObjects boInfoObjects2 = (IInfoObjects)infoStore.query("Select * FROM CI_SYSTEMOBJECTS WHERE SI_ID = " + boUserIterator.next());
  IUser boUser = (IUser)boInfoObjects2.get(0);
 
  // Don't touch the Administrator or Guest user accounts or the source User if they are part of the group
  if (!(boUser.getTitle().equals("Administrator") || boUser.getTitle().equals("Guest")))
  {
   IUserAliases boAliases = boUser.getAliases();
   IUserAlias myAlias = boAliases.addExisting(AliasType + ":" + boUser.getTitle(),AliasType + ":#" + boUser.getID(), isDisabled);
  }
  infoStore.commit(boInfoObjects2);
}
}
out.println("Completed</br>");

%>

28 Comments