I have spent some hours now on a little problem that I now solved but don't really understand.
I want to get an array of all usergroups (security) that a user is NOT already assigned to.
Here is what I did first:
var groups = security.getGroups().getColumnAsArray(2);
var groups_chosen = security.getUserGroups(uid_user_servoy).getColumnAsArray(2);
var removed;
for ( var i = 0 ; i < groups.length ; i++ )
{
for ( var j = 0 ; j < groups_chosen.length ; j++ )
{
if (groups[i] == groups_chosen[j])
{
removed = groups.splice(i , 1);
}
}
}
In my example, there is 3 groups (Administrators, Users, Test). The user I am testing with is in Administrators and Users. The result should be "Test". But with the above code, the result is "Test, Users, Users".
Now I do this:
var thegroups = security.getGroups().getColumnAsArray(2);
var groups = new Array();
for (k = 0; k < thegroups.length; k++)
{
groups[k] = thegroups[k]
}
var thegroups_chosen = security.getUserGroups(uid_user_servoy).getColumnAsArray(2);
var groups_chosen = new Array();
for (l = 0; l < thegroups_chosen.length; l++)
{
groups_chosen[l] = thegroups_chosen[l]
}
var removed;
for ( var i = 0 ; i < groups.length ; i++ )
{
for ( var j = 0 ; j < groups_chosen.length ; j++ )
{
if (groups[i] == groups_chosen[j])
{
removed = groups.splice(i , 1);
}
}
}
And that works as intended.
Can someone explain to me the difference between the Array "groups" from the upper code and the Array "groups" from the lower code? Or does getColumnAsArray deliver "some other type of Array"?
Thanks for your time.
Patrick