Is the actor in a specific custom role

I’ve been searching around for a while and haven’t been able to figure this out.

I have a queue that has a custom role “Approvers”. What I want to do is set the ticket status to open if the ticket status is “approval” AND a user in the “Approvers” custom role comments on the ticket.

So far I have this very basic condition

return 0 unless $self->TransactionObj->Type eq "Comment";
return 0 unless $self->TicketObj->Status eq "approval";
return 1;

So I have the “this is a comment” and “the current status is approval” conditions ticked off - I cannot see if there is a way to tell if the user is in a custom role.

Can anybody help?

Thanks
James

You could use the CreatorObj() method on $self->TransactionObj (which RT::Transaction inherits from RT::Record) to get the RT::User object for the person creating the transaction. You can use this to get the email address of the user that created the transaction, and then compare that to the list of email addresses returned from the RoleAddresses() method call on $self->TicketObj.

So maybe something like this (not tried it so take it with a pinch of salt!):

my $thisEmail = $self->TransactionObj->CreatorObj->EmailAddress;
return 0 unless($self->TicketObj->RoleAddresses('Approvers') =~ /$thisEmail/);
1 Like

Thanks for your suggestion.

I gave this a go, but $self->TicketObj->RoleAddresses('Approvers'); just returns an empty string. I have tested by replacing 'Approvers' with 'Requestors', and this does return results.

Do we need to do something extra to get this information from a custom role?

I got it. I found this old post Accessing role object from template, and the solution is to call RT::CustomRole-1 instead of the role name, ‘1’ being the ID of the custom role.

return 0 unless $self->TransactionObj->Type eq "Comment";

return 0 unless $self->TicketObj->Status eq "approval";

my $thisEmail = $self->TransactionObj->CreatorObj->EmailAddress;

# Get list of email addreses in the "Approvers" custom role by ID. 
# Custom Role Approvers ID = 1
my $ticketApprovers = $self->TicketObj->RoleAddresses('RT::CustomRole-1');

return 0 unless $ticketApprovers =~ /$thisEmail/;
1 Like