Status change scrip action

I’m trying to write a scrip that runs on a status change. I’m trying
to change the owner to Nobody if a ticket is reopened, and I have the
following code in the action prep area:

my $oldStatus = $self->TransactionObj->OldValue;
my $newStatus = $self->TicketObj->status;

if (($oldStatus eq ‘resolved’) and ($newStatus eq ‘open’) {
$self->TicketObj->OwnerObj = RT::Nobody()->id();
}

I’ve run a couple tests through, but nothing seems to be happening.
First, what’s the best way to debug custom action code? Second, if
anyone seems what I’m doing wrong, feel free to point it out.

Steve

Well, with the help of the book and the wiki, I have the code to
change the user back to nobody on a reopened ticket at least trying to
do what it’s supposed to. Unfortunately, it got the following error:

[Mon Jan 21 05:38:47 2008] [error]: Failed changing owner to Nobody on
ticket reopen: You can only reassign tickets that you own or that are
unowned ((eval 831):10)

is there some way to force the scrip to reassign the ticket by acting
as a user with more controls?

SteveOn Jan 21, 2008, at 12:03 AM, Steve Cochran wrote:

I’m trying to write a scrip that runs on a status change. I’m trying
to change the owner to Nobody if a ticket is reopened, and I have
the following code in the action prep area:

my $oldStatus = $self->TransactionObj->OldValue;
my $newStatus = $self->TicketObj->status;

if (($oldStatus eq ‘resolved’) and ($newStatus eq ‘open’) {
$self->TicketObj->OwnerObj = RT::Nobody()->id();
}

I’ve run a couple tests through, but nothing seems to be happening.
First, what’s the best way to debug custom action code? Second, if
anyone seems what I’m doing wrong, feel free to point it out.

Steve


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly
Media.Buy a copy at http://rtbook.bestpractical.com

You need to force the owner change to Nobody:

Keep up with my goings on at http://theillien.blogspot.com

Steve Cochran wrote:

Hi RT Users,
Just a simple questions (hopefully). Inside a scrip i can get the CF
Value with: $Ticket->FirstCustomFieldValue(‘CFNAME’). If i need to the
the corresponding Description to this value, can i get this with:
$Ticket->FirstCustomFieldValue(‘CFNAME’)->Description ?!?

Small Background to this. I need to create a small workflow for our
Development Department. A Business Unit creates a ticket and needs to
set some CF’s. Dependeing on a Custom Field called “Module” a
responsible System Analyst will be informed.

My Idea is a small Scrip like this:

Condition: OnCreate
Action: SendEmail (from BPS WIKI)
Template: LocalCorrespond

A new ticket has been created in queue .

{$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
{$Transaction->Content()}

Inside this local Correspond Template i would like to use this
$Ticket->FirstCustomFieldValue(‘CFNAME’)->Description to get the correct
SystemAnalyst.

The Idea behind is a Mapping of Module → System Analyst. This has also
the big advantage, that i can grant AdminCustomField to the Department
and they can administrate all the mappings by themself…

CF: Module
Values:

1: Module A Description: SystemAnalyst1@company.com
2: Module B Description: SystemAnalyst2@company.com
3: Module C Description: SystemAnalyst3@company.com
4: Module D Description: SystemAnalyst4@company.com

OK, now the Problem, the Idea above is not working:

Jan 21 13:36:56 bruchtal-www3 RT: Template parsing error: Can’t call
method “Description” on an undefined value at template line 1. Stack:
[template:1] [/opt/rt3/lib/RT/Template_Overlay.pm:392]
[/opt/rt3/lib/RT/Template_Overlay.pm:313]
[/opt/rt3/lib/RT/Action/SendEmail.pm:120]
[/opt/rt3/lib/RT/ScripAction_Overlay.pm:234]
[/opt/rt3/local/lib/RT/Scrip_Overlay.pm:493]
[/opt/rt3/lib/RT/Scrips_Overlay.pm:239]
[/opt/rt3/lib/RT/Transaction_Overlay.pm:173]
[/opt/rt3/lib/RT/Record.pm:1461]
[/opt/rt3/lib/RT/Ticket_Overlay.pm:746]
[/opt/rt3/lib/RT/Interface/Web.pm:461]
[/opt/rt3/local/html/Ticket/Display.html:71]
[/opt/rt3/local/html/Ticket/Create.html:353]
[/opt/rt3/share/html/autohandler:291]
(/opt/rt3/lib/RT/Template_Overlay.pm:388)

Any Ideas???

Thanks

Torsten
Kuhne + Nagel (AG & Co.) KG, Geschaftsleitung: Hans-Georg Brinkmann (Vors.), Uwe Bielang (Stellv.), Bruno Mang, Alfred Manke, Thorsten Meincke, Mark Reinhardt (Stellv.), Jens Wollesen, Rainer Wunn (Stellv.), Sitz: Bremen, Registergericht: Bremen, HRA 21928, USt-IdNr.: DE 812773878, Personlich haftende Gesellschaft: Kuhne & Nagel A.G., Sitz: Contern/Luxemburg Geschaftsfuhrender Verwaltungsrat: Klaus-Michael Kuhne

Hi RT Users,
Just a simple questions (hopefully). Inside a scrip i can get the CF
Value with: $Ticket->FirstCustomFieldValue(‘CFNAME’). If i need to the
the corresponding Description to this value, can i get this with:
$Ticket->FirstCustomFieldValue(‘CFNAME’)->Description ?!?

Should be:

$Ticket->CustomFieldValues(‘CFNAME’)->First->Description

I think …

Emmanuel Lacour ------------------------------------ Easter-eggs
44-46 rue de l’Ouest - 75014 Paris - France - M�tro Gait�
Phone: +33 (0) 1 43 35 00 37 - Fax: +33 (0) 1 41 35 00 76
mailto:elacour@easter-eggs.com - http://www.easter-eggs.com

Hi Emmanuel,
The error message is getting better :wink:

Jan 21 13:53:30 bruchtal-www3 RT: Template parsing error: Can’t locate object method “First” via package “Shipment” (perhaps you forgot to load “Shipment”?) at template line 1. Stack: [template:1]

This is the correct Template, without any replacements:

A new ticket has been created in queue HAM.WEBDEV.KNLOGIN.SUPPORT.

{$RT::WebURL}Ticket/Display.html?id={$Ticket->id}

{$Transaction->Content()}

Created is the Ticket with the CF: Occured in Module set to Shipment.

Torsten

Hi Emmanuel,
The error message is getting better :wink:

Jan 21 13:53:30 bruchtal-www3 RT: Template parsing error: Can’t locate object method “First” via package “Shipment” (perhaps you forgot to load “Shipment”?) at template line 1. Stack: [template:1]

This is the correct Template, without any replacements:

To: {$Ticket->FirstCustomFieldValue(‘Occured in Module’)->First->Description;}

You didn’t write exactly what I said :wink: “$Ticket->CustomFieldValues”, not “$Ticket->FirstCustomFieldValue”.

See the function FirstCustomFieldValue in lib/RT/Record.pm to understand it.

Emmanuel Lacour ------------------------------------ Easter-eggs
44-46 rue de l’Ouest - 75014 Paris - France - M�tro Gait�
Phone: +33 (0) 1 43 35 00 37 - Fax: +33 (0) 1 41 35 00 76
mailto:elacour@easter-eggs.com - http://www.easter-eggs.com

Shame on me… :frowning:

Tryed it out with this (re read your Mail :wink: !)

A new ticket has been created in queue HAM.WEBDEV.KNLOGIN.SUPPORT.

{$RT::WebURL}Ticket/Display.html?id={$Ticket->id}

{$Transaction->Content()}

And i get this error now :frowning:

Jan 21 14:38:14 bruchtal-www3 RT: Template parsing error: RT::ObjectCustomFieldValue::Description Unimplemented in T. (template line 1) Stack: [/usr/lib/perl5/site_perl/5.8.5/DBIx/SearchBuilder/Record.pm:496] [template:1] [/opt/rt3/lib/RT/Template_Overlay.pm:392] [/opt/rt3/lib/RT/Template_Overlay.pm:313] [/opt/rt3/lib/RT/Action/SendEmail.pm:120] [/opt/rt3/lib/RT/ScripAction_Overlay.pm:234] [/opt/rt3/local/lib/RT/Scrip_Overlay.pm:493] [/opt/rt3/lib/RT/Scrips_Overlay.pm:239] [/opt/rt3/lib/RT/Transaction_Overlay.pm:173] [/opt/rt3/lib/RT/Record.pm:1461] [/opt/rt3/lib/RT/Ticket_Overlay.pm:746] [/opt/rt3/lib/RT/Interface/Web.pm:461] [/opt/rt3/local/html/Ticket/Display.html:71] [/opt/rt3/local/html/Ticket/Create.html:353] [/opt/rt3/share/html/autohandler:291] (/opt/rt3/lib/RT/Template_Overlay.pm:388)

Argh…sometimes…

Torsten

Shame on me… :frowning:

Tryed it out with this (re read your Mail :wink: !)

To: {$Ticket->CustomFieldValues(‘Occured in Module’)->First->Description;}
Subject: {$Ticket->Subject}

A new ticket has been created in queue HAM.WEBDEV.KNLOGIN.SUPPORT.

{$RT::WebURL}Ticket/Display.html?id={$Ticket->id}


{$Transaction->Content()}

And i get this error now :frowning:

Jan 21 14:38:14 bruchtal-www3 RT: Template parsing error: RT::ObjectCustomFieldValue::Description Unimplemented

Argh, it seems that we don’t have access to description in this kind of
object (RT::ObjectCustomFieldValue) :frowning:

No more idea :-/

Emmanuel Lacour

:wink: OK, then i have to go the hard way…but hopefully jesse or one of the RT developers read this mails :wink:

Thanks

Torsten

Ham & Torsten,

I just caught the tail-end of your inquiry. If I understand your 

dilema, you are trying to get a CF called description into your
notification template? If so, we use the following code that works quite
well for us:

This ticket has been resolved. DO NOT reply to this message!
TICKET INFORMATION:
Ticket Queue : {$Ticket->QueueObj->Name}
Ticket Number : {$Ticket->Id}
Ticket Subject: {$Ticket->Subject}
Ticket Description:
{
return $Ticket->FirstCustomFieldValue(‘Description’);
}
Ticket Priority is: {$Ticket->Priority}
Ticket Created by: {$Ticket->CreatorObj->Name}
Ticket Created on: {substr($Ticket->Created, 0, 10)}
Ticket Owned by: {$Ticket->OwnerObj->Name}
Development Started on: {substr($Ticket->Started, 0, 10)}
QA Approved on: N/A
QA Approved by: N/A
Migrated on: {substr($Ticket->Resolved, 0, 10)}
Migrated by: {$Ticket->LastUpdatedByObj->Name}
Resolution comment:
{
my $Resolution_Comment;
my $Transactions;
my $CommentObj;

   $Transactions = $Ticket->Transactions;
   $Transactions->Limit( FIELD => 'Type', VALUE => 'Comment' );
   $Transactions->OrderByCols(
       { FIELD => 'Created',  ORDER => 'DESC' },
       { FIELD => 'id',     ORDER => 'DESC' },
       );

   $CommentObj = $Transactions->First;

   if  ($CommentObj && $CommentObj->id)
   {
        $Resolution_Comment = $CommentObj->Content;
   }
   else
   {
        $Resolution_Comment = "No comment."
   }

   return $Resolution_Comment;

}
To view ticket information, enter URL:

 {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}


Please notice we pick up two different comments in the template and use 

two different styles as well. We use this as a model for grabbing CF’s
for a template. Anyway, hope this helps.

Kenn
LBNLOn 1/21/2008 7:34 AM, Ham MI-ID, Torsten Brumm wrote:

:wink: OK, then i have to go the hard way…but hopefully jesse or one of the RT developers read this mails :wink:

Thanks

Torsten

K�hne + Nagel (AG & Co.) KG, Gesch�ftsleitung: Hans-Georg Brinkmann (Vors.), Uwe Bielang (Stellv.), Bruno Mang, Alfred Manke, Thorsten Meincke, Mark Reinhardt (Stellv.), Jens Wollesen, Rainer Wunn (Stellv.), Sitz: Bremen, Registergericht: Bremen, HRA 21928, USt-IdNr.: DE 812773878, Pers�nlich haftende Gesellschaft: K�hne & Nagel A.G., Sitz: Contern/Luxemburg Gesch�ftsf�hrender Verwaltungsrat: Klaus-Michael K�hne

-----Urspr�ngliche Nachricht-----

Von: Emmanuel Lacour [mailto:elacour@easter-eggs.com]
Gesendet: Montag, 21. Januar 2008 16:23
An: Ham MI-ID, Torsten Brumm
Cc: rt-users@lists.bestpractical.com
Betreff: Re: [rt-users] Simple Question: CustomField of Type
SelectOneValue /How to get the Description from a Scrip/Template?

On Mon, Jan 21, 2008 at 03:40:08PM +0100, Ham MI-ID, Torsten Brumm wrote:

Shame on me… :frowning:

Tryed it out with this (re read your Mail :wink: !)

To: {$Ticket->CustomFieldValues(‘Occured in
Module’)->First->Description;}
Subject: {$Ticket->Subject}

A new ticket has been created in queue HAM.WEBDEV.KNLOGIN.SUPPORT.

{$RT::WebURL}Ticket/Display.html?id={$Ticket->id}


{$Transaction->Content()}

And i get this error now :frowning:

Jan 21 14:38:14 bruchtal-www3 RT: Template parsing error:
RT::ObjectCustomFieldValue::Description Unimplemented

Argh, it seems that we don’t have access to description in
this kind of object (RT::ObjectCustomFieldValue) :frowning:

No more idea :-/


Emmanuel Lacour


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Hi Emmanuel,
Sorry, no. I mean, if you create a CF of Type Select one Value, you can enter additional Desciption for it. I tried to get the Description Values to put into a template.

Let me explain more in Detail:

I have a CF called Module which is mandatory with the following Options:

  1. Module 1 Description: usera@company.com
  2. Module 2 Description: userb@company.com
  3. Module 3 Description: userc@company.com
  4. Module 4 Description: userd@company.com

If now a user creates a new Ticket via WebUI, he has to select a value.

In this case, i don’t want to inform all queue Watchers about the new tickets, only the person depending on the choice the Ticket Creator has used.

Torsten