Assign Custom Field Value to Owner on Ticket Creation

I am attempting to create a custom action that is a bit over my head. The idea is that there is a custom field Call Center Agent, which holds an email address. If that email address matches one of the email addresses in a certain user group, then the ticket would be automatically assigned to that user on creation. In pseudocode something like this.

On Create
{
If UserGroup contains CF.CallCenterAgent
then assign CF.CallCenterAgent to Ticket Owner
}

The one other thing that might complicate this is that CallCenterAgent is also assigned during ticket creation, so ideally this action would run at the end or after the rest of the ticket creation code. I’m not sure if that is controllable.

It may also be helpful to know that the usernames are all email addresses so they should be exact matches of the callcenteragent values.

Any help with this would be much appreciated.

Quick question, is there a reason to use a custom field for CallCenterAgent instead of a custom role? Either works but the custom role approach allows you to confirm the value entered is a user in RT

Possibly not. Currently we are making the tickets from an external application that automatically fills in the CallCenterAgent custom field with the user information from whoever is signed into that external application. I don’t understand custom roles that well but likely the only advantage to it being a custom field is that I can show it in the RT chart, or as a column in an RT search which is helpful when I’m making reports.

I didn’t test this but I think this is the idea:

my $CallCenterAgentName = $self->TicketObj->FirstCustomFieldValue( 'CallCenterAgent' );
my $CallCenterAgent = RT::User->new( RT->SystemUser );
my ($ret, $msg) = $CallCenterAgent->Load( $CallCenterAgent );
unless ( $ret ) {
    RT::Logger->error( "Could not load user: $CallCenterAgentName: $msg" );
    return;
}

my $group = RT::Group->new( RT->SystemUser );
($ret, $msg) = $group->Load( 'Some Group' );
unless ( $ret ) {
    RT::Logger->error( "Could not load group 'some group': $msg" );
    return;
}

if ( $group->HasMember( $CallCenterAgent->PrincipalId ) ) {
    ($ret, $msg) = $self->TicketObj->SetOwner( $CallCenterAgent );
    RT::Logger->error( "Could not load group 'some group': $msg" ) unless $ret;
    return $ret;
}
return;

That seems like it should work, and it doesn’t give me any errors, but it didn’t do anything when I tried to test it. I’m wondering if it has to do with the order of operations when the ticket is made, is there any way to make sure the Scrip is run just after ticket creation?

Maybe a custom condition instead of On Create?

I think it should be there on create, you can print the value using RT::Logger->error() to confirm