Page 1 of 1

Placing Array into a Global

PostPosted: Thu May 20, 2004 1:30 pm
by Clive Sanders
This may seem a simple task to you experts out there, but I am having problems finding out how to place the contents of an array into a global field.

Firstly, I am getting all the current UserGroups by doing the following:

Code: Select all
var Groups = security.getGroups();
var showArray = new Array(Groups.getMaxRowIndex());
for ( var i = 0 ; i < Groups.getMaxRowIndex() ; i++ )
showArray[i] = Groups.getValue(i + 1, 2);


How do I then place the Array contents into a global field?

PostPosted: Thu May 20, 2004 2:18 pm
by Clive Sanders
I should add, that what I want to do is to display the UserGroupID and UserGroup Name, i.e.

1 GroupNameA
2 GroupNameB

etc. etc.

Thanks for your help

PostPosted: Thu May 20, 2004 4:19 pm
by maarten
You can directly "paste" the values into a global

Code: Select all
var Groups = security.getGroups();
globals.myGlobal = "";
for ( var i = 1 ; i <= Groups.getMaxRowIndex() ; i++ )
{
   globals.myGlobal += Groups.getValue(i, 1) +" "+Groups.getValue(i, 2)+"\n";
// ID + GroupName + "backslash new line"
}

PostPosted: Thu May 20, 2004 4:25 pm
by Clive Sanders
That's brilliant. Thanks very much.

One other small point, is it possible to sort the Array into GroupName alpha sequence.

PostPosted: Thu May 20, 2004 5:01 pm
by maarten
This code sorts on group name.
It first captures the dataset values in a separate array,
which is then sorted before sent to the global.
Bit of a workaround.
I'll ask dev team if they can add a sort method to the Dataset object
myDataset.sort(columnName/Nr);

Code: Select all
var Groups = security.getGroups();

var groupsArray = new Array()

globals.myGlobal = "GROUPNAME\tID\n"; \\backslash t stands for TAB
for ( var i = 1 ; i <= Groups.getMaxRowIndex() ; i++ )
{
   //capture values in array
   groupsArray[i-1] = Groups.getValue(i, 2) +"\t"+Groups.getValue(i, 1);
}

groupsArray.sort(); //sort the array

//loop through the array and  fill the global
for ( var i = 0 ; i < groupsArray.length ; i++ )
{
   globals.myGlobal += groupsArray[i]+"\n";
}