Adding New Transaction from scrip

Hello all,Using a custom scrip action, I send sms messages to the new owner of a ticket when they are assigned a ticket (On Owner Change.)

I have researched on the web, browsed this mailing list, and went through the perldoc of Ticket.pm, Transaction.pm, etc.

I cannot find a way to simply add a transaction to the history of the ticket.

For example the ideal thing to be able to do would be to add a new transaction like when it says:

The RT System Itself - Outgoing email recorded

and attaches the message.I would like it to say The RT System itslef - Outgoing SMS recordedor something similiar and attach the sms message.

But all I absolutely need is to be able to somehow record in the history that the message was sent.

From looking at the code, it seems that I should not create a transaction object directly but use ticket methods to do so, but I don’t see any ticket methods that will create a new transaction!

If anyone can offer some help, or a step in the right direction, I would appreciate it.

Kory PrinceBullard ISD

(Sorry for the previous email. My work email client is terrible.)

Hello all,Using a custom scrip action, I send sms messages to the new
owner of a ticket when they are assigned a ticket (On Owner Change.)

I have researched on the web, browsed this mailing list, and went
through the perldoc of Ticket.pm, Transaction.pm, etc.

I cannot find a way to simply add a transaction to the history of the ticket.

For example the ideal thing to be able to do would be to add a new
transaction like when it says:
The RT System Itself - Outgoing email recorded

and attaches the message.I would like it to say

The RT System itself - Outgoing SMS recorded
or something similiar and attach the sms message.

But all I absolutely need is to be able to somehow record in the
history that the message was sent.

From looking at the code, it seems that I should not create a
transaction object directly but use ticket methods to do so, but I
don’t see any ticket methods that will create a new transaction!

If anyone can offer some help, or a step in the right direction, I
would appreciate it.
Kory Prince
Bullard ISD

(Sorry for the previous email. My work email client is terrible.)

Hello all,Using a custom scrip action, I send sms messages to the new
owner of a ticket when they are assigned a ticket (On Owner Change.)

I have researched on the web, browsed this mailing list, and went
through the perldoc of Ticket.pm, Transaction.pm, etc.

I cannot find a way to simply add a transaction to the history of the ticket.

For example the ideal thing to be able to do would be to add a new
transaction like when it says:
The RT System Itself - Outgoing email recorded

and attaches the message.I would like it to say

The RT System itself - Outgoing SMS recorded
or something similiar and attach the sms message.

But all I absolutely need is to be able to somehow record in the
history that the message was sent.

From looking at the code, it seems that I should not create a
transaction object directly but use ticket methods to do so, but I
don’t see any ticket methods that will create a new transaction!

You want to use the _NewTransaction method available on Records.
You can trace through the Correspond method on Tickets to get a sense
of how it’s typically used.

-kevin

You want to use the _NewTransaction method available on Records.
You can trace through the Correspond method on Tickets to get a sense
of how it’s typically used.

-kevin

Thanks Kevin.
Now correct if I’m wrong, but in order to have my own transaction
type, I would have to Edit Transaction.pm (or do a local copy on top
of it) to add it. What I eventually decided on was just adding a
comment from the system user. Here is my final script for anyone
interested:

#Taken partly from
http://kermit.yaxs.net/post/2061563927/request-tracker-quick-n-dirty-sending-sms-on-change

load the ticket, owner and user object

my $Ticket = $self->TicketObj;
my $OwnerID = $self->TicketObj->Owner;
my $user = RT::User->new($RT::SystemUser);

set the requestor email and ticket subject - will be used in the SMS

my $Requestor = $Ticket->RequestorAddresses;
my $Subject = $Ticket->Subject;

load owners details and grab the mobile number from RT

$user->Load($OwnerID);
my $OwnerMobileNumber = $user->MobilePhone;

check if we have a mobile number for the new owner, leave a log

message and quit if we dont
if ( !$OwnerMobileNumber ) {
$RT::Logger->info ( ‘Not sending notification SMS - no mobile number
found for owner’);
return 1;
}

some logging so we can check it’s working

$RT::Logger->info ( 'Sending SMS to ‘.$OwnerMobileNumber.’, ticket
subject is ‘.$Ticket->Subject.’ requested by
'.$Ticket->RequestorAddresses );

ticket id

my $url = $RT::WebURL . “m/ticket/show?id=” . $Ticket->Id;

and backticks to exec the sms script

python /opt/notify.py \"$OwnerMobileNumber\" \"Ticket assigned:\n $Requestor: $Subject\" \"$url\";
$self->TicketObj->Comment(
Content=>“Outgoing SMS Sent:\nTicket assigned:\n $Requestor: $Subject”
);
return 1;

Thanks
Kory Prince
Bullard ISD

Just adding a note to this thread as I stumbled upon this and worked out how to use RT::Record::_NewTransaction in my extension, and it might help others - I know I’m going to use it in a few other places!

In the .pm file for your extension add something like:

{
    package RT::Transaction;
    our %_BriefDescriptions;

    $_BriefDescriptions{"PagerDuty-Create"} = sub {
        return "Event created in PagerDuty";
    };
}

Now when you call $ticket->_NewTransaction you can refer to PagerDuty-Create. But note, you are limited to 20 characters due to the column in the database being a varchar(20).

For an example, see: RT-Extension-PagerDuty/NotifyPagerDuty.pm at master · catalyst-cloud/RT-Extension-PagerDuty · GitHub

I still need to work out if I can disable Reply, Comment & Forward when displaying this transaction in the ticket history.

Edit: And to give credit, I found the example of adding to %_BriefDescription on RT::Extension::Assets.

1 Like