Scrips - Getting the user that created the ticket

Hello, I’ve made a scrip that runs when a ticket is created. Is there a way to get the username of the user that create the ticket?

In a script $self->TicketObj gives you the RT::Ticket object that the scrip has been fired on. This means you can use any of the methods for that object. The slight complication is that an RT ticket can have more than one requestor. There is a Requestor() method on RT::Ticket that returns an RT::Group constructed from the requestors. So if you use:

my $requestors = $self->TicketObj->Requestor->MembersObj();

you’ll get an RT::GroupMembers object of all the requestors. You can then iterate through this to get the individual RT::GroupMember objects, which point to an RT::Principal object that in turn will point to the RT::User object. At this point you can get the username.

while (my $thisRequestor = $requestors->Next()) {
my $thisUser = $thisRequestor->MemberObj->Object();

my $thisUsername = $thisUser->Name();

# Do something cool with $thisUsername.


If you want requestor email addresses rather than usernames, things are a bit simpler: RT::Ticket has a RequestorAddresses() method that returns all the requestor email addresses as a string. You could use this as an alternative to get the usernames by splitting it into individual email addresses and then using the RT::User object `` LoadByEmail method to load each user.

The creator could be another User-ID than requestors. Imagine a member of a service-desk who creates tickets for incomming callers.

So it should be something regarding the creator() method: $self->TicketObj->Creator();

I’m not at my desk to test it at the moment. It should give a user-id you can use to use the user-object and access all user-attributes.

1 Like