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
Former Member
0 Kudos

Perfect job, thank you!

 

I am newbe in BOE SDK world.

 

What should i do for execute this scripts? 

former_member203619
Contributor
0 Kudos

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

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

Former Member
0 Kudos

Excellent bit of information. All in One documentation.

 

Thanks for sharing

Former Member
0 Kudos

I just ran the script from above to convert users to named/concurrent in 4.1 SP1 and it worked just fine. I copy pasted to a txt, modified the file, and saved as a .jsp within the tomcat webapps AdminTools folder and ran it via a browser -> http://server:8080/AdminTools/script.jsp

 

Thought maybe people would want to know it works fine in newest BI4 version 😉

former_member208314
Discoverer
0 Kudos

I am unable to execute the Add Aliases script using the technique Chad suggested.

 

Get the following error:

 

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: com.crystaldecisions.sdk.occa.infostore.internal.InfoStoreException: Invalid alias ID secEnterprise:<username>.  cause:com.crystaldecisions.enterprise.ocaframework.idl.OCA.oca_abuse: IDL:img.seagatesoftware.com/OCA/oca_abuse:3.2 detail:Invalid alias ID secEnterprise:<username>.  The server supplied the following details: Failed to commit object 'username'. Reason: Enterprise alias id does not conform to format secEnterprise:#<ObjectID>.   org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 

root cause

javax.servlet.ServletException: com.crystaldecisions.sdk.occa.infostore.internal.InfoStoreException: Invalid alias ID secEnterprise:<username>.  cause:com.crystaldecisions.enterprise.ocaframework.idl.OCA.oca_abuse: IDL:img.seagatesoftware.com/OCA/oca_abuse:3.2 detail:Invalid alias ID secEnterprise:<username>.  The server supplied the following details: Failed to commit object 'username'. Reason: Enterprise alias id does not conform to format secEnterprise:#<ObjectID>.   org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791) org.apache.jsp.addalias_jsp._jspService(addalias_jsp.java:133) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 

 

Can someone suggest what may be the issue?

The user ids are loaded with secLDAP.  We need to assign secEnterprise to all of them.

Former Member
0 Kudos

I adjusted the code for AliasType secEnterprise a bit:

// Activate if AliasType = secEnterprise
IUserAlias myAlias = boAliases.addExisting(AliasType + ":" + boUser.getTitle(),AliasType + ":" + "#" + boUser.getID(), isDisabled);

 

Now it is working fine.

mhf
Active Participant
0 Kudos

Hello Community,

 

i am trying to run the AddAlias script on 4.1, but i receive the following error if the progam tries to commit the changes to the database:

The server supplied the following details: Failed to commit object 'userName'. Reason: Enterprise alias id does not conform to format secEnterprise:#<ObjectID>.

Does someone know how to fix this?

 

Thanks & BR,

 

Michael

former_member203619
Contributor
0 Kudos

Please see Silvan's modification.  I have updated the code to reflect the updated alias format.

former_member203619
Contributor
0 Kudos

Thanks - I have modified the code to reflect this.  The change must have occurred when going from XI R3 to BI4.

Former Member
0 Kudos

Hi,

 

I was trying to use your Change Owner script and had a couple of questions.

 

I want to change the owners of instances to a generic owner. That way, if the report writer leaves and is removed from the system, their reports will keep running.  I think this script will do that.

 

However, I was wondering why in the guery of the CI_INFOOJECTS, you have the following in the where clause.

 

AND SI_ID > "+ max_id +" AND SI_ID =2528

 

What is the point of the max_id?  and why is the si_id hard coded to 2538?  I think that might be a mistake.

 

Also, I don't understand the point of the two for loops.

 

You are looking for a specific user.  Doesn't the query return all of the needed rows? The iterator should take care of updaing all of those.

 

What is the point of setting si_id to the last max id in the list?  doesn't that just exit us from the outer loop? 

 

Or is there something I am missing?

 

thanks

 

 


former_member203619
Contributor
0 Kudos

The SI_ID =2528 was accidentally left there from when I was testing the script - so I have removed it.

 

As for the point of having two loops - by default an infostore query will only return up to 1000 objects.  So if there are more than 1000 objects on the enterprise system, then the script will not apply to all objects.  Normally I include a "TOP 500" as part of the infostore query to make this more obvious - but I must have left it out in this example.

 

In short, the outside loop does multiple queries - each of which return up to 1000 items which are owned by a specific user (SI_ID = 12345) and are crystal reports.  The max_id variable stores the SI_ID value of the last object looked at by the previous loop.  Since the query orders things by SI_ID (ORDER BY SI_ID ASC), that ensures that previous objects will not be included in subsequent loops.  It finally breaks out when no objects are returned by the query.

former_member184512
Participant
0 Kudos

Excellent  information. All in One documentation.

 

Really thanks for sharing!!!

Former Member
0 Kudos

I tried using add Alias code for secEnterprise and I get "Invaild alias ID secEnterprise:ldap.first." error. I changed secEnterprise to secLDAP and it add the alias. is there different syntax for secEnterprise? the BO version is 4.1 SP6. I did verify that secEnterprise alias did not exist prior to executing the script. Any direction would be greatly appreciated

Former Member
0 Kudos

Thanks!! I tried Disable User group script and it doesn't seem to be working. It executes but doesn't disable the users from the group.

 

Thanks

former_member208338
Discoverer
0 Kudos

Hi ,

 

We have very recently migrated to BI 4.1 from XIR3. We need to update the option "User cannot change password" for all the enterprise users in CMC. Please advise how to perform it with a script without doing it manually .we have around 1300 users.

 

Thanks in advance

Former Member
0 Kudos
Have a look at this link  http://scn.sap.com/message/16675236
Former Member
0 Kudos
Is the code converting Named to concurrent is working for BO 3.1 ?
former_member186752
Participant
0 Kudos

Hey Shawn

 

Amazing job!

Could you please let me know if it’s possible to automate the execution of the scripts?

I have the “copy user preferences globally” script in mind and we would like to schedule it to be executed on a daily basis. The execution should be performed without human interaction.

 

Cheers

M

former_member341172
Participant
0 Kudos
Hi everyone,

Any ideas how to modify the script to make changes only to "Database Credentials" for all BO users except administrator and guest? I would like to change the password and confirm it.

Thank you in advance,

Vytas

 
Joe_Peters
Active Contributor
boUser.addSecondaryCredential("<database username>","<database password>")
Former Member
0 Kudos
Hello Everyone,

 

I'm trying to run the change to concurrent script.  I want to do this for all users, so I left the Everyone group in the script.  When I run it, I'm getting the message "No groups found with name Everyone".  I tried eliminating the variable groupName and replaced it with the actual group name Everyone, but I received the same error message.

Any ideas???
Former Member
0 Kudos
Hi All,

Any Idea how to modify the script to add "secSAP" aliases of a new system to an existing SAP alias

For example  Mapping SAP A alias SID~ACLNT/USER01” and SAP B alias “SID~BCLNT/USER01” using the script.
former_member189544
Contributor
Hi Marian,

 

you should encapsulate the code into a Java program object, that can be uploaded to the BI Platform and that can be scheduled similar to a report-object without user interaction. This is not a big deal.

For an example of such a Java program object look here:

https://blogs.sap.com/2014/12/01/extract-usergroups-information-using-java-program-objects/

Regards,

Harald
former_member189544
Contributor
0 Kudos
Hi Dennis,

maybe you have your BIP running on a non english OS. E.g. on a german system the everyone-group may be called "Alle"...

You could query for the Everone-Group by the SI_ID, which is usually 1.

Regards,

Harald

 
former_member189544
Contributor
0 Kudos
Hi Arindam,

the Alias Type would be "secSAPR3" and the alias itself would have the form: secSAPR3:[SID]~[CLNT]/[USERNAME].

If you just want to map the same users from different SAP systems or clients, than you should consider the solution described here:

1781355 - How to automatically alias SAP users from different multiple system to users existing in B...

Regards,

Harald

 
0 Kudos

Hello Friends ,

Is there a way to disable a user  after a specified time duration , i have created an SAP self serve password reset app using SDK and it resets the password of a user with random password and emails it to him , and marks password to change on next logon as true.

i want  to limit it for a time duration with in which that random password is valid and he has to change , else disable account.

 

Thanks

VinodBhat
Explorer
0 Kudos
Hi Shawn,

Very helpful blog.

I have specific requirement to copy favorites folder from one alias to from one user to other.

 

Thanks & BR,

Vinod
former_member203619
Contributor
0 Kudos
A favorites folder is considered a special folder in BOE - so I don't believe you can copy the actual folder from one user to another.  What you can do instead is just change the SI_PARENTID property of the objects in the root of the one favorites folder to the ID of the target favorites folder.  That should move the objects over.