Placing Custom Fields into the Subject

Hi,

We have messages coming in with a generic subject, and we’re using ExtractCF to pull out important information from the body into the Custom Fields, which works amazing.
But I’d like to re-write the subject with some of the information contained in the custom fields…

Does anyone have an example on how to do this?
I assume it’s a Scrip, On Create, running after our ExtractCF scrip…

Thanks,

Chad Osmond

We have messages coming in with a generic subject, and we’re using ExtractCF to pull out
important information from the body into the Custom Fields, which works amazing.

But I’d like to re-write the subject with some of the information contained in the custom
fields…

Does anyone have an example on how to do this?

I assume it’s a Scrip, On Create, running after our ExtractCF scrip…

Yes, it’s an On Create with a User Defined action, Prepare would be 1;
and Commit would call $self->TicketObj->SetSubject() passing in the
data you want.

-kevin

Date: Fri, 9 Mar 2012 08:33:22 -0500
From: Chad Osmond Chad.Osmond@compfitness.com
Subject: [rt-users] Placing Custom Fields into the Subject

Hi,

We have messages coming in with a generic subject, and we’re using
ExtractCF to pull out important information from the body into the Custom
Fields, which works amazing.
But I’d like to re-write the subject with some of the information
contained in the custom fields..

Does anyone have an example on how to do this?
I assume it’s a Scrip, On Create, running after our ExtractCF scrip…
Thanks,
Chad Osmond

Just implemented such a scrip here last week. We set the subject to the
concatenation of two custom fields, Report Type and Report.
After the scrip executes, the subject appears as Report Type: Report

Description: 001 On Create, Set Subject to CF Values
Condition: On Create
Action: User Defined
Template: Global template: Blank
Stage: TransactionCreate
Custom Condition:

set the subject to Report Type : Report

my $subject = $self->TicketObj->FirstCustomFieldValue(‘Report Type’) .
': ’ .
$self->TicketObj->FirstCustomFieldValue(‘Report’) ;

$self->TicketObj->SetSubject($subject) ;

We may end up using TransactionBatch, as we have several other scrips that
run On Create. The description has a 001 prefix to set the order for the
scrips to be executed (I read that somewhere, ).

Sharon Belliveau
Federal Reserve Board

But I’d like to re-write the subject with some of the information contained in the custom fields…
I assume it’s a Scrip, On Create, running after our ExtractCF scrip…

Yes, it’s an On Create with a User Defined action, Prepare would be 1; and Commit would call $self->TicketObj->SetSubject() passing in the data you want.

I’ve created a scrip in the Global and in the Queue itself to try and get this working…

So far I have:

Description: " 020 - Set subject based on custom field"
Condition: On Create
Action: User Defined
Template: Global Template: Blank
Stage: Transaction Create

Custom Condition:
$RT::Logger->info(“Running Scrip #020 Set Subject”);
my $subject = $self->TicketObj->FirstCustomFieldValue(‘Address’);
my ($status, $msg) = $self->TicketObj->SetSubject($subject) ;
unless ( $status ) {
$RT::Logger->error(“Couldn’t change the subject due to: $msg”);
return 0;
}
return 1;

Custom action prepare code:
return 1;

Custom action cleanup code:
return 1;

I set the logging in RT to debug, and I can see the scrip executing after the extraction of custom fields… (It’s #15) but the subject isn’t set…

[info]: CustomFieldValue (Pager, 025 ) added: 237 (/opt/rt4/local/plugins/RT-Extension-ExtractCustomFieldValues/lib/RT/Action/ExtractCustomFieldValues.pm:213)
[debug]: Committing scrip #15 on txn #1451 of ticket #194 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:192)
[debug]: Committing scrip #3 on txn #1451 of ticket #194 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:192)
[debug]: Committing scrip #4 on txn #1451 of ticket #194 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:192)
[debug]: Calling SetRecipientDigests for transaction RT::Transaction=HASH(0x7f1ad539b878), id 1451 (/opt/rt4/sbin/…/lib/RT/Action/SendEmail.pm:641)
[debug]: Working on mailfield To; recipients are (/opt/rt4/sbin/…/lib/RT/Action/SendEmail.pm:657)
[debug]: Subject: [RT #194] test 11

But I’d like to re-write the subject with some of the information contained in the custom fields…
I assume it’s a Scrip, On Create, running after our ExtractCF scrip…

Yes, it’s an On Create with a User Defined action, Prepare would be 1; and Commit would call $self->TicketObj->SetSubject() passing in the data you want.

I’ve created a scrip in the Global and in the Queue itself to try and get this working…

So far I have:

Description: " 020 - Set subject based on custom field"
Condition: On Create
Action: User Defined
Template: Global Template: Blank
Stage: Transaction Create

This code is for a User Defined condition, you have a User Defined
action, so you need to delete the code from this box

Custom Condition:
$RT::Logger->info(“Running Scrip #020 Set Subject”);
my $subject = $self->TicketObj->FirstCustomFieldValue(‘Address’);
my ($status, $msg) = $self->TicketObj->SetSubject($subject) ;
unless ( $status ) {
$RT::Logger->error(“Couldn’t change the subject due to: $msg”);
return 0;
}
return 1;

Custom action prepare code:
return 1;

And put it in this box (the cleanup box)

Custom action cleanup code:
return 1;

I set the logging in RT to debug, and I can see the scrip executing after the extraction of custom fields… (It’s #15) but the subject isn’t set…

RT will never execute the code in Custom Condition because your
Condition is On Create (which is correct). RT is executing your
custom action code, which consists only of a true value to indicate
success.

-kevin

Ack! Error in the previous email (not custom condition, should be custom
action):
Description: 001 On Create, Set Subject to CF Values
Condition: On Create
Action: User Defined
Template: Global template: Blank
Stage: TransactionCreate

Custom Action Preparation Code:

set the subject to Report Type : Report

my $subject = $self->TicketObj->FirstCustomFieldValue(‘Report Type’) .
’: ’ .
$self->TicketObj->FirstCustomFieldValue(‘Report’) ;

$self->TicketObj->SetSubject($subject) ;

Sharon Belliveau
Federal Reserve Board