Skip to Content
author's profile photo Former Member
Former Member

How to get list of groups user belongs to

Hello,

is there a Crystal Reports function that would return list of BusinessObjects groups logged user belongs to ? (I mean the BusinessObjects groups assigned to user in CMC).

Example: I need to conditionally supress objects based on user's groups - if he belongs to group AAA, he can see certain object on a report, otherwise he can't.

If there's by default no such a function (which I'm afraid is the case), can a custom Java based function be created using BusinessObjects SDK ? Anyone did that, has the code and is willing to share it ? Or, is there a better workaround ?

Thanks,

Jakub

Add a comment
10|10000 characters needed characters exceeded

Related questions

5 Answers

  • Best Answer
    Posted on Feb 07, 2011 at 07:06 PM

    JSP code continued from previous post:

    
                             if (setUserGroups.size() == 0)
    	    		{
    	    			out.println("There are no user groups that the user " + retrieveUserName + " belongs to.<br \\>");
    	    		}
    	    		else
    	    		{
    	    			Iterator iter = setUserGroups.iterator();
    	    		    
    	    			// To store the group ID.
    	    			Object groupID = null;
    	    			
    	    			// To store the group name.
    	    			String groupName = null;
    	    			
    	    			while (iter.hasNext())
    	    			{
    	    				groupID = iter.next();
    	    					    				
    	    				// Get the name of the group.
    	    				queryGroupString = "SELECT * FROM CI_SYSTEMOBJECTS WHERE SI_KIND = 'UserGroup' AND SI_ID = '" + groupID + "'";
    	    				
    	    				// Execute the query of the InfoStore.
    	    			    boGroupInfoObjects = boInfoStore.query(queryGroupString);
    	    				
    	    			 	// Retrieve the first entry.
    	    			 	boGroupInfoObject = (IInfoObject) boGroupInfoObjects.get(0);
    	    			 	
    	    			 	// Get the group name.
    	    			 	groupName = boGroupInfoObject.getTitle();
    	    			 	
    	    			 	// Print out the ID aqnd name of the group.
    	    				out.println("The ID of the group is " + groupID + " and the name of the group is " + groupName + ".<br \\>");
    	    			 }
    	    		}
    		  	}
    	    	else
    	    	{
    	    		out.println("A query of the InfoStore for the user returned 0 InfoObjects.<br \\>");
    	    	}
    	    }
    	    else
    	    {
    	    	 out.println("A query of the InfoStore for the user returned null.<br \\>");
    	    }
    	}
    	catch (Exception ex)
    	{
    		// Set the message to be displayed to the user to indicate that an
    		// error has occurred and display the error message.
    		out.println("An error was encountered.  A description of the error"
    				+ " is as follows:  " + ex.toString());
    		// Log the error and the stack trace to the system out log file
    		System.out.println("An error was encountered.  A description of the "
    						+ "error is written below:");
    		System.out.println(ex);
    		System.out.println("The stack trace for the error is written below:");
    		ex.printStackTrace(System.out);
    	}
    	
    	// If the logon was previously successful, then logoff.
    	if (boEnterpriseSession != null)
    	{
    		boEnterpriseSession.logoff();
    	}
    %>
    
    
    

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 07, 2011 at 05:31 PM

    In the Java Enterprise SDK, there is a class called IUserBase that has a function called getGroups() that returns a collection of groups that the user belongs to. So if you wrote a custom java application that returns you the user that you are interested in, you could use the getGroups() function to return you the Groups that the user belongs to.

    Regards.

    - Robert

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 07, 2011 at 07:03 PM

    I am attaching the contents of a jsp file here that will log a user onto the Enterprise and for an enter user name, will retrieve and display the Group IDs and Group Names that the user belongs to. I will attach the contents of the jsp over the next two posts because all of the contents will not fit into a single post.

    Here is the contents;

    <%
    /*************************** GetUserGroups.jsp ******************************** 
     * 
     * This jsp will log the user onto the Enterprise, retrieve a user InfoObject
     * based on a user name, then retrieve the groups that the user belongs
     * to, and then print out the group IDs and names.
     *
     *****************************************************************************/
    %>
    
    <%@ page import = "com.crystaldecisions.sdk.framework.*,
    				   com.crystaldecisions.sdk.occa.infostore.IInfoStore,
    				   com.crystaldecisions.sdk.occa.infostore.IInfoObject,
    				   com.crystaldecisions.sdk.occa.infostore.IInfoObjects,
    				   com.crystaldecisions.sdk.framework.IEnterpriseSession,
    				   com.crystaldecisions.sdk.plugin.desktop.user.*,
    				   java.util.*"
    %>
    
    <%
    	// Declarations
    	
    	// Business Object Declarations.
    	IEnterpriseSession boEnterpriseSession = null;
    	ISessionMgr boSessionMgr = null;
    	IInfoStore boInfoStore = null;
    	IInfoObjects boUserInfoObjects = null;
    	IInfoObject boUserInfoObject = null;
    	IUser boUser = null;
    	IInfoObjects boGroupInfoObjects = null;
    	IInfoObject boGroupInfoObject = null;
    	
    	// To store the collection of user groups that the user is a part of.
    	Set setUserGroups = null;
    	
    	// To store the ID of the report that we are querying for
    	String retrieveUserName = "<Enter the name of the user that you want to determine the groups that the user belongs to here>";
    	
    	// Logon Information
    	String logonUserName = "<Enter Enterprise logon User Name here>";
    	String password = "<Enter Password Here>";
    	String cmsName = "<Enter CMS Name Here>";
    	String authType = "<Enter Authentication Type Here - eg. secEnterprise>";
    	
    	String queryUserString = null;
    	
    	String queryGroupString = null;
    	
    	// Try block that will catch an Exception.
    	try 
    	{			
    		// Initialize the Session Manager by getting it from the Crystal Enterprise
    		// class's getSessionMgr function.
    		boSessionMgr = CrystalEnterprise.getSessionMgr();
    		
    		// Logon to the Session Manager to create a new BOE session.  Pass in the
    		// user name, password, the CMS name, and the authentication
    		// type.
    		boEnterpriseSession = boSessionMgr.logon(logonUserName, password, cmsName, authType);
    
    	    //Retrieve the InfoStore object
    	    boInfoStore = (IInfoStore) boEnterpriseSession.getService("", "InfoStore");
    	    
    	    // Set up the query string.
    	    queryUserString = "SELECT * FROM CI_SYSTEMOBJECTS WHERE SI_KIND = 'User' AND SI_NAME = '" + retrieveUserName + "'";
    	    
    	   	// Execute the query of the InfoStore.
    	    boUserInfoObjects = boInfoStore.query(queryUserString);
    	   	
    	    if (boUserInfoObjects != null)
    	    {
    	    	// A query of the InfoStore did not return null.
    	    	
    	    	if (boUserInfoObjects.size() != 0)
    	    	{
    	    		// A query of the InfoStore returned at least one InfoObject.
    	    		
    	    		// Retrieve the first entry.
    				boUserInfoObject = (IInfoObject) boUserInfoObjects.get(0);
    	    		
    	    		// Cast the User Info Object to IUser so that we can retrieve the groups that the
    	    		// user is a part of.
    	    		boUser = (IUser) boUserInfoObject;
    	    		
    	    		// Retrieve the collection of user groups that the user belongs to.
    	    		setUserGroups = boUser.getGroups();
    	    		
    	    		// Print out the user groups that the user belongs to.
    				out.println("The IDs and names of the user groups that the user " + retrieveUserName + " belongs to are:<br \\>");
    	    		
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 07, 2011 at 08:09 PM

    Thanks a lot, gonna try.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 22, 2011 at 04:22 PM

    There is an undocumented Business Objects query function that may help you with this, too. But again, this is undocumented, so use at your own risk. It does work, I just can't gurantee that it'll be around in future versions of BOE, and this may be unsupported by SAP support.

    The relevant query is:

    SELECT SI_ID, SI_NAME FROM CI_SYSTEMOBJECTS WHERE SI_KIND='UserGroup' AND SELECTUSINGPROPERTY(<SI_ID of user>,SI_ID,SI_USERGROUPS,SI_ID)

    This query will return the names and SI_IDs of all groups to which the user belongs.

    HTH.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.