Identifying current user membership in a security group

Is there a function available to show what security groups a particular user currently belongs to?

The following produces unexpected results:

var usergroups = security.getUserGroups(userid);
var groups = security.getGroups();

The debugger reports both variables identically as:

JSDataSet size:3,selectedRow -1

Morley:
Is there a function available to show what security groups a particular user currently belongs to?

The following produces unexpected results:

var usergroups = security.getUserGroups(userid);

var groups = security.getGroups();


The debugger reports both variables identically as:

> JSDataSet size:3,selectedRow -1

They both return an array of groups, you have to use the first function to view the groups a user belongs to.
Try this:

var usergroups = security.getUserGroups(userid);
for ( var i = 0 ; i <= usergroups.length ; i++ )
{
   application.output(usergroups[i])
}

ngervasi:
They both return an array of groups, you have to use the first function to view the groups a user belongs to.
Try this:

var usergroups = security.getUserGroups(userid);

for ( var i = 0 ; i <= usergroups.length ; i++ )
{
application.output(usergroups[i])
}

Produces this error:

java.lang.ArrayIndexOutofBoundsException

I suspect the culprit is “<= usergroups.length”, a style of looping I’m not familiar with.

Morley:
I suspect the culprit is “<= usergroups.length”, a style of looping I’m not familiar with.

Sorry, I was in a hurry. You get a DataSet not an array, take a look at this code:

// Set up the global fields with the user groups

var user_id = globals.sintpro_sec_selected_uid

var user_groups = security.getUserGroups(user_id)
var groups_array = new Array()

for ( i = 1 ; i <= user_groups.getMaxRowIndex() ; i++ )
	{
		groups_array[i-1] = user_groups.getValue(i,1)
	}

globals.sintpro_sec_groups = groups_array.join('\n')

You can use this to populate a global field with the groups a user belongs to separated by CR and to learn how to convert a dataset into an array.

Hope this helps.