Placing Array into a Global

Questions, tips and tricks and techniques for scripting in Servoy

Placing Array into a Global

Postby Clive Sanders » Thu May 20, 2004 1:30 pm

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?
Clive Sanders
 
Posts: 92
Joined: Mon Jan 26, 2004 7:42 pm

Postby Clive Sanders » Thu May 20, 2004 2:18 pm

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
Clive Sanders
 
Posts: 92
Joined: Mon Jan 26, 2004 7:42 pm

Postby maarten » Thu May 20, 2004 4:19 pm

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"
}
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby Clive Sanders » Thu May 20, 2004 4:25 pm

That's brilliant. Thanks very much.

One other small point, is it possible to sort the Array into GroupName alpha sequence.
Clive Sanders
 
Posts: 92
Joined: Mon Jan 26, 2004 7:42 pm

Postby maarten » Thu May 20, 2004 5:01 pm

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";
}
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands


Return to Methods

Who is online

Users browsing this forum: No registered users and 9 guests