CustomField change if keyword is on the subject

I would like to inquire how to create a script that
On create
if subject contains "Payroll"
Customfield ‘Support Type’ will be changed to payroll.

Please advise.

Thanks.

I just managed my first scrip that updates a custom field, so I figured that I’d take a stab at answering this.

First, got to Admin > Scrips > Create

Give your scrip a Description.

In the Condition drop-down, select ‘On Create’

In the Action drop-down, select ‘User Defined’

Finally, you’ll need to populate Custom action preparation code: and Custom action commit code:

In this case, I’ve chosen ‘On Create’ as your condition. I guess that it would be possible to create a custom condition that would combine ‘On Create’ with testing the subject for the word “Payroll”, but I’m going to take the path of least resistance, and put the following in the Custom action preparation code:

my $Ticket = $self->TicketObj;
my $Transaction = $Ticket->Transactions->First;
if( $Transaction->Subject =~ /Payroll/ ) {
    return 1
} else {
    return 0
}

This should look at the subject of the first transaction, and return true if it contains “Payroll”, and false otherwise. The commit code won’t execute if the preparation returns false.

Set the Support Type custom field in the commit code:

my $Ticket = $self->TicketObj;
my $CF = RT::CustomField->new( $RT::SystemUser );
$CF->LoadByNameAndQueue( Name => 'Support Type', Queue => $Ticket->Queue );
$CF->AddValueForObject( Object => $Ticket, Content => 'payroll' );

Finally, set Template to Blank and click Create

I’ve tested the code in so far as that I can verify that a ticket created with a subject containing “Payroll” did in fact populate Support Type with payroll.