Initialdata: Adding members to a group

Hi All!

Is it possible to import members to an existing group via initaldata file. The file looks like this below

    our @Groups = ();

    push @Groups, {
        Name        => 'Queue_RW',
        Description => 'Members with read/write rights',
        Members     => { Users =>  [ qw/ alexmv trs falcone / ]},
    };

Thanks

The docs use that example so I assume it should work, you could make a test group and try it so see and then delete that group if something is wrong

Hi, knation

I got this message in syslog

Apr  7 12:25:58 3d335c255eff RT: [207] Group name 'Queue_RW' is already in use

Oh sorry i didn’t read that the group exists, you’d need to do a @Final block and load then add the users to the group:

our @Final = (sub {
    my $group = RT::Group->new( RT->SystemUser );
    my ($ret, $msg) = $group->LoadUserDefinedGroup( 'Queue_RW' );

    die $msg unless $ret;

    my $userObj = RT::User->new( RT->SystemUser );
    foreach my $user ( qw/ alexmv trs falcone/ ) {
        ($ret, $msg) = $userObj->Load( $user );
        unless ( $ret ) {
              print "Couldn't load $user\n";
            next;
        }
        ($ret, $msg) = $group->AddMember( $userObj->PrincipalId );
        print" $msg\n";
    }
});

Hi, knation

Thanks, it works!