Finding the current user for a reply (scrips)

I’m trying to write a scrip to set a ticket’s status based on who
replies to it - if it’s staff, set it to stalled, if it’s not, set to open.

I currently have an OnCorrespond condition, and a custom Action, but I’m
not seeing the user I expect from the Transaction object.

$RT::Logger->warning(“Welcome to Scrip 13”);

get actor ID

my $trans = $self->TransactionObj;
my $Ticket = $trans->TicketObj;
my $Actor = $self->CurrentUser();

$RT::Logger->warning(ref($Ticket)." ".ref($Actor));

if actor is RT_SystemUser then get out of here

return 1 if $Actor == $RT::SystemUser->id;

$RT::Logger->warning("Actor is ".$Actor->Name);

my $staff = 0;

my $GroupObj = RT::Group->new($Actor);
$GroupObj->LoadUserDefinedGroup( ‘RTUsers’ );

my $PrincipalObj = RT::Principal->new($Actor);
$PrincipalObj->Load($Actor->id);

$RT::Logger->warning("groupname: ".$GroupObj->Name); #Remove them from
production
$RT::Logger->warning("principaltype: ".$PrincipalObj->PrincipalType);

if ($GroupObj->HasMemberRecursively($PrincipalObj)) {
$staff = 1;
$self->TicketObj->SetStatus(‘stalled’);
$RT::Logger->warning(“Staff”);
}
else
{
$RT::Logger->warning(“Non-staff”);
}

return 1;

and the log output is:
Oct 8 16:49:31 rt RT: Welcome to Scrip 13 ((eval 759):1)
Oct 8 16:49:31 rt RT: RT::Ticket RT::CurrentUser ((eval 759):9)
Oct 8 16:49:31 rt RT: Actor is RT_System ((eval 759):14)
Oct 8 16:49:31 rt RT: groupname: RTUsers ((eval 759):26)
Oct 8 16:49:31 rt RT: principaltype: User ((eval 759):27)
Oct 8 16:49:31 rt RT: Non-staff ((eval 759):36)

even though I am triggering this by replying to a ticket logged in as a
normal user (in the RTUsers group) from the web UI. Why is it ‘RT_System’?

Can someone please point me in the right direction? I think I’m probably
missing something fundamental…

Thanks,

Howie

I’m trying to write a scrip to set a ticket’s status based on who
replies to it - if it’s staff, set it to stalled, if it’s not, set to open.

I currently have an OnCorrespond condition, and a custom Action, but I’m
not seeing the user I expect from the Transaction object.

$RT::Logger->warning(“Welcome to Scrip 13”);

get actor ID

my $trans = $self->TransactionObj;
my $Ticket = $trans->TicketObj;
my $Actor = $self->CurrentUser();

Try using $trans->Creator or $trans->CreatorObj
Scrips run in a system context, but the creator of the transaction
will be the user who triggered it.

-kevin

Try using $trans->Creator or $trans->CreatorObj
Scrips run in a system context, but the creator of the transaction
will be the user who triggered it.

Thanks! That did the trick…

So for the sake of anyone else searching later, here is the final scrip.
There’s already another scrip that sets the status back to open on
correspondence.

get actor ID

my $trans = $self->TransactionObj;
my $Ticket = $trans->TicketObj;
my $Actor = $trans->CreatorObj();

if actor is RT_SystemUser then get out of here

return 1 if $Actor == $RT::SystemUser->id;

All staff users are in ‘RTUsers’.

my $GroupObj = RT::Group->new($Actor);
$GroupObj->LoadUserDefinedGroup( ‘RTUsers’ );

my $PrincipalObj = RT::Principal->new($Actor);
$PrincipalObj->Load($Actor->id);

if ($GroupObj->HasMemberRecursively($PrincipalObj)) {
if($Ticket->Status() eq ‘open’)
{
$self->TicketObj->SetStatus(‘stalled’);
}

}

return 1;