Setting Due Dates from E-mail and writing Comments to transaction history from Custom Scrips

Hi all,

Two problems I’ve been bashing my head against a wall with - any and all assistance appreciated!

Problem 1: Setting the Due Date based on input from an E-mail
We’re using web-forms to generate e-mails into RT which presents the information in an organised and standard manner.

An example is below:

Door Times Request Form :

Details:

Campus: Parkville
Door Name: 203
Door Name: TEST JOB - DISREGARD

Open Date: 21/08/2013
Open Time: 18:00

Close Date: 21/08/2013
Close Time: 19:00

Building Supervisor: Testy McTest Alot
Department/Faculty Representitive: Campus Operations Group

Requested By: Dave Fitches
Email: dfitches@unimelb.edu.au

Comments: Test job to get due date set for start date as defined by web form.

I want to grab the "Open Date: " date and set it to the ticket’s DUE date (Id actually prefer to have to due the day BEFORE that, but lets work on one thing at a time shall we!)

I’m using ExtractCustomFieldValues running to pluck information from these e-mails.

My template goes something like this:

Set the jobs Due Date from E-mail Body

|Body|(?<=Open Date: ).*|my $due_date = $value; $due_date->Set(Format => “ISO”, Value => $value); $self->TicketObj->SetDue( $due_date->ISO );|q|

This does NOT work for me… :frowning:
Instead I get: " [Mon Aug 19 04:47:17 2013] [error]: Can’t call method “Set” on an undefined value at (eval 1293) line 1. " in my logs…

Problem #2: Writing a comment to the transaction history

I’ve got automatic e-mails being sent to requestors on status changes (we go from New->Open->Ordered->Dispatched->Resolved)
The e-mail goes out ok, but I’d like it to log a comment to the transaction history that says so.
While it shows up in my main HISTORY display, my DISPLAY history is masked to only show comments and correspondence, so I’d like a single comment line there to make seeing whats happened easier…

I’ve got a custom scrip which goes like this:
DESCRIPTION: On Ordered Notify Requestors
CONDITION: User Defined
ACTION: Notify Requestors and CC’s
TEMPLATE: Auto-Report - Ordered
STAGE: TransactionCreate

            CUSTOM CONDITIONS:
                            my $txn = $self->TransactionObj;

my $type = $txn->Type;
return 0 unless $type eq “Status”
|| ( $type eq ‘Set’ && $txn->Field eq ‘Status’);

return 0 unless $txn->NewValue eq “ordered”;
return 1;

                            CUSTOM ACTION PREPARATION CODE:


                            CUSTOM ACTION CLEANUP CODE:
                                            $self->TicketObj->Comment(Content =>"Notification sent to original requestor that their order has been processed."

);

return 1;

I suspect the issue is in the cleanup code… But it LOOKS correct! (to me - but I’m a n00b apparently!)

Sorry for such a long e-mail. Again, any assistance would be greatly appreciated!

Dave Fitches
This email and any attachments may contain personal information or information that is otherwise confidential or the subject of copyright. Any use, disclosure or copying of any part of it is prohibited. The University does not warrant that this email or any attachments are free from viruses or defects. Please check any attachments for viruses and defects before opening them. If this email is received in error please delete it and notify us by return email. And I’m only using this signature template because I’m told I must conform. Personally I liked my old one better - but that’s life! :wink:

My template goes something like this:

**


Set the jobs Due Date from E-mail Body****

|Body|(?<=Open Date: ).*|my $due_date = $value; $due_date->Set(Format
=> “ISO”, Value => $value); $self->TicketObj->SetDue( $due_date->ISO );|q|



This does NOT work for me… L ****

Instead I get: “ [Mon Aug 19 04:47:17 2013] [error]: Can’t call method
“Set” on an undefined value at (eval 1293) line 1. “ in my logs…

$due_date needs to be an RT::Date object in order to use set or ISO. Is
it?

ie:
$due_date = new RT::Date( $self->CurrentUser );
$due_date->Set(Format => “ISO”, Value => $value);
$self->TicketObj->SetDue( $due_date->ISO );

Since your dates are not in ISO format I’d probably recommend using Format
=> ‘unknown’ to set the RT::Date figure it out. It takes a few extra
cycles but provides flexibility when needed.

I use this:
my $Due = new RT::Date( $self->CurrentUser );
$Due->Set( Format => ‘unknown’, Value => ‘now + 24 hours’);
$ticket->SetDue($Due->ISO);


Problem #2: Writing a comment to the transaction history****


While it shows up in my main HISTORY display, my DISPLAY history is masked
to only show comments and correspondence, so I’d like a single comment line
there to make seeing whats happened easier…****

                                CUSTOM ACTION CLEANUP CODE:

**


$self->TicketObj->Comment(Content =>"Notification sent to original
requestor that their order has been processed."****

);****

I suspect the issue is in the cleanup code…. But it LOOKS correct! (to me
– but I’m a n00b apparently!)

If I’m understanding you correctly and if memory serves me I think you
can just add RecordTransaction => 1 to the end of this and it’ll do what
you want. I know this works for AddCustomFieldValue() but I’m not 100%
sure if it works for Comment(). Worth a try though.

$self->TicketObj->Comment(Content =>“Notification sent to original
requestor that their order has been processed.”, RecordTransaction => 1);

Landon Stewart LandonStewart@Gmail.com

Hey Landon,

Thanks a heap for the feedback.

Problem 1 is now FIXED thanks to you!

Final code for the ExtractCustomFieldValues template for those who are interested, ended up being:

            # Set the jobs Due Date from E-mail Body

|Body|(?<=Open Date: ).*|my $Due = new RT::Date( $self->CurrentUser ); $Due->Set(Format => “unknown”, Value => $value); $Due->AddDays( -1 ); $self->TicketObj->SetDue( $Due->ISO );|q|

Though I did then have some interesting hic-cups with it arguing with the SLA mod…
When the E-mail Value Extract was picking up the date, the SLA mod was promptly altering it. Ended up having to remove the default SLA, manually define the SLA for all other queues (not a BAD thing) and then create a new scrip for on CREATE to make it set the STARTS date otherwise the Priority Escalate process wouldn’t work…<!!>

As for Problem 2 - your suggestion sadly didn’t work.

Dave Fitches
Security Software Administrator | Security Systems | Property and Campus Services
BN203, 213-215 Grattan Street
The University of Melbourne, Victoria 3010, Australia
T +61 3 8344 9232 | M +61 411 811 525 | F +61 3 9349 5175 | dfitches@unimelb.edu.aumailto:dfitches@unimelb.edu.au | securitysystems.unimelb.edu.auhttp://securitysystems.unimelb.edu.au/
[cid:image001.png@01CDDD27.F59750D0]
This email and any attachments may contain personal information or information that is otherwise confidential or the subject of copyright. Any use, disclosure or copying of any part of it is prohibited. The University does not warrant that this email or any attachments are free from viruses or defects. Please check any attachments for viruses and defects before opening them. If this email is received in error please delete it and notify us by return email. And I’m only using this signature template because I’m told I must conform. Personally I liked my old one better - but that’s life! ;)From: Landon [mailto:landonstewart@gmail.com]
Sent: Tuesday, 20 August 2013 3:35 AM
To: Dave Fitches
Cc: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Setting Due Dates from E-mail and writing Comments to transaction history from Custom Scrips

My template goes something like this:

Set the jobs Due Date from E-mail Body

|Body|(?<=Open Date: ).*|my $due_date = $value; $due_date->Set(Format => “ISO”, Value => $value); $self->TicketObj->SetDue( $due_date->ISO );|q|

This does NOT work for me… :frowning:
Instead I get: " [Mon Aug 19 04:47:17 2013] [error]: Can’t call method “Set” on an undefined value at (eval 1293) line 1. " in my logs…

$due_date needs to be an RT::Date object in order to use set or ISO. Is it?

ie:
$due_date = new RT::Date( $self->CurrentUser );
$due_date->Set(Format => “ISO”, Value => $value);
$self->TicketObj->SetDue( $due_date->ISO );

Since your dates are not in ISO format I’d probably recommend using Format => ‘unknown’ to set the RT::Date figure it out. It takes a few extra cycles but provides flexibility when needed.

I use this:
my $Due = new RT::Date( $self->CurrentUser );
$Due->Set( Format => ‘unknown’, Value => ‘now + 24 hours’);
$ticket->SetDue($Due->ISO);

Problem #2: Writing a comment to the transaction history
While it shows up in my main HISTORY display, my DISPLAY history is masked to only show comments and correspondence, so I’d like a single comment line there to make seeing whats happened easier…
CUSTOM ACTION CLEANUP CODE:
$self->TicketObj->Comment(Content =>“Notification sent to original requestor that their order has been processed.”
);
I suspect the issue is in the cleanup code… But it LOOKS correct! (to me - but I’m a n00b apparently!)
If I’m understanding you correctly and if memory serves me I think you can just add RecordTransaction => 1 to the end of this and it’ll do what you want. I know this works for AddCustomFieldValue() but I’m not 100% sure if it works for Comment(). Worth a try though.

$self->TicketObj->Comment(Content =>“Notification sent to original requestor that their order has been processed.”, RecordTransaction => 1);

Landon Stewart <LandonStewart@Gmail.commailto:LandonStewart@Gmail.com>