How do I add new correspondence to ticket from script action?

Hi,

I was trying to search but failed. Here is what I’d like to achieve:

I have a script that is triggered when Start or Due field is modified in a ticket and this has the following condition under “Custom condition:”:

my $ticket = $self->TicketObj;
return 0 unless ($self->TransactionObj->Type eq "Set" && ($self->TransactionObj->Field eq "Starts" || $self->TransactionObj->Field eq "Due"));
return 1;

This part works properly i.e. the script is triggered.

What I would like now is to have a custom action that would automatically add a correspondence to this ticket that would contain some additional message like:

Please note that Start or Due date has been changed
Your current Start date: 2025-09-04 14:00
Your current Due date: 2025-09-10 18:00

I can’t figure out how to add new correspondence from such script. Any help apprieciated

Does adding such correspondance in a script triggers in parallel automatically “On Correspond” script or this acction is just executed and visible i ticket history (that’s what I’d like to achieve) ?

best regards,
Szymon

If you create a new transaction (such as correspondence or comment), then you should cause a new cascade of scrips to be processed for that. So in your case, the new correspondence will trigger any “OnCorrespond” at least (and maybe others if you have custom conditions that also match).

You don’t know how to insert a transaction? You need to understand RT’s classes and methods to get the right entry.

In your Scrip you use “CustomAction”

In “PreparationCode” you need a return 1. “PreparationCode” is used before the transaction is applied.

In “CommitCode” you can use the usual methods to get the dates and insert a Comment or Reply.

Example:

my $ticket = $self->TicketObj;
my $due_date = ...;
my $comment = "Your current Due date: ". $due_date;

($transaction, $msg) = $ticket->Comment(Content => $comment);
unless ($transaction) {
			RT::Logger->error("Any error-message: " . $msg);
		}

Hi,

Thank you for suggestion. For the simplicity of debugging I put the following into “Custom Action Commit Code”:

my $ticket = $self->TicketObj;
my $comment = "Please note that Start or Due date has been changed";
($transaction, $msg) = $ticket->Correspond(Content => $comment);
unless ($transaction) {
			RT::Logger->error("Any error-message: " . $msg);
}

Then, when I change the Start date the script is triggered properly (I got mail from template). However the History page in RT ticket Gui doesn’t show any additional transaction/correspondance containing the above comment just Set action and info that email was sent:

Thu Sep 18 14:58:41 2025 root (System Administrator) - Starts changed from Thu Sep 04 04:00:00 2025 to Thu Sep 04 10:00:00 2025

Am I doing something wrong to display this created transation?

Regards,

Szymon

The transaction is a usual transaction an should appear.
I think you need to return 1;, anyway. Maybe that’s the point.

After this there are many things tha can trigger

Is the user allowed to see comments?
Use history instead of display and look there.
Is there anything in rt.log?
If “SeeOutgoingMail” is enabled, do you see the mail?

Regards, Andre.

Hi Andre,

I added to “Custom action commit code:” the following:

my $ticket = $self->TicketObj;
my $comment = "Please note that Start or Due date has been changed";
($transaction, $msg) = $ticket->Correspond(Content => $comment);
unless ($transaction) {
			RT::Logger->error("Any error-message: " . $msg);
}
return 1;

In the RT web interface under ticket’s History I can’t see any transaction - just info about changing fields values and email sent:

The content of the email sent by a template used by this script is using the following logic to display transactions:

{$Transaction->Content() . "\n";}

but it prints “This transaction appears to have no content” in the email sent

Yes, user is allowed to see comments
I’m looking at history
Yes, email is triggered but also doesn’t contain the transaction content
Nothing special in the log

In fact I’m a bit lost here :frowning:

regards,
Szymon