cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help with Script

Former Member
0 Kudos

Hi All,

We have a requirement to obtain the groups associated with a particular set of users and I have found the following query:

Select SI_ID, SI_NAME From CI_SYSTEMOBJECTS Where PARENTS("SI_NAME='UserGroup-User'","SI_NAME='Administrator'")

but the number of users in question is large and running this query for each user would be extremely time consuming.

I have modified one of the existing script with this query and would be grateful if someone could help with printing the results:

Code I have is as below and I am skeptical about the part highlight in bold red font:

---------------------------------------------------------------------------------------

/*

* Path to file containing User names.

*/

final String USER_FILE_PATH = "C://Userlist.txt";

IEnterpriseSession enterpriseSession;

enterpriseSession = null;

try

{

IInfoStore infoStore;

IInfoObjects newInfoObjects;

IInfoObject oInfoObject;

BufferedReader fin;

enterpriseSession = CrystalEnterprise.getSessionMgr().logon(BO_USER_NAME, BO_PASSWORD, BO_CMS_NAME, BO_AUTH_TYPE);

infoStore = (IInfoStore) enterpriseSession.getService("", "InfoStore");

fin = new BufferedReader(new FileReader(USER_FILE_PATH));

for(;;)

{

  String username;

  /* Read file for user name */

  username = fin.readLine();

  if(username == null)

  {

   break;

  }

  username = username.trim(); // Trim surrounding spaces.

  out.println("User: " + username + "<BR>");

  // Query to see if the user exists.

String boQuery = "Select SI_ID, SI_NAME From CI_SYSTEMOBJECTS Where PARENTS(\"SI_NAME='UserGroup-User'\",\"SI_NAME='+username+"'\")"

  IInfoObjects boResults = (IInfoObjects)infoStore.query(boQuery);

  if (!boResults.isEmpty())

  {

  

   IUser user = (IUser)boResults.get(0);

    

   out.print("Groups of user : " + username + " <BR>");

   out.print("<br>SI_ID: "+boResults.SI_ID+"<BR>SI_NAME:  "+boResults.SI_NAME);

  }

  else

  {

   out.print("User " + username + " does not exists.<BR>");

  }

}

fin.close();

}

Thanks a lot!

Regards,

Mihir

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Mihir,

Do you see any error while executing the above script ?

You can also check below link which might help with your requirement.

http://scn.sap.com/docs/DOC-6258

Let us know if you have any queries.

Thanks,

Rameez Shaikh

Former Member
0 Kudos

Hi Rameez,

I get the following error:

Unable to compile class for JSP: An error occurred at line: 45 in the jsp file: /printUserGroups.jsp Invalid character constant 42: username = username.trim(); // Trim surrounding spaces. 43: out.println("User: " + username + "<BR>"); 44: // Query to see if the user exists. 45: String boQuery = "Select SI_ID, SI_NAME From CI_SYSTEMOBJECTS Where PARENTS(\"SI_NAME='UserGroup-User'\",\"SI_NAME='+username+"'\")" 46: 47: IInfoObjects boResults = (IInfoObjects)infoStore.query(boQuery); 48: if (!boResults.isEmpty()) Stacktrace:

Thanks,

Mihir

Former Member
0 Kudos

Use the below code

String sq = "Select SI_ID, SI_NAME From CI_SYSTEMOBJECTS Where PARENTS(\"SI_NAME='UserGroup-User'\",\"SI_NAME='"+username+"'\")";

IInfoObjects iObjects = iStore.query(sq);

IInfoObject iObject = null;

out.print("Groups of user : " + username + " <BR>");

for(int i=0;i<iObjects.size();i++)

{

  iObject = (IInfoObject)iObjects.get(i);

   out.print("<br>SI_ID: "+iObject.getID()+"<BR>SI_NAME:  "+iObject.getTitle());

}

Thanks,

Prithvi