We need to add a bunch of users to a group. We have already created the group in Admin console. We created a script to add the users to the group but that doesn't seem to work - after running the script, we do not see the group in the group tab for the user account. Can anyone suggest what we are doing wrong in the following snippet?

for k,v in pairs(myuser) do if type(v) == "boolean" then if v == true then myuser[k] = 1 else myuser[k] = 0 end end end

if myuser.usergroups ~= nil then local bGroupExisted = false for _,tempgroup in pairs(myuser.usergroups) do if tempgroup.groupname == group.groupname then bGroupExisted = true end end if bGroupExisted == false then table.insert(myuser.usergroups, group) end else myuser.usergroups = {} table.insert(myuser.usergroups, group) end