Problem with trigger

Hi,

I’m trying to write a trigger for a particular custom field, as
described at
http://wiki.bestpractical.com/view/OnCustomFieldValueChange, and
apparently I don’t understand something. I’d appreciate any
enlightenment anyone can offer, pointers to docs I should read, etc.

I have a CustomField called “Port Completion”. When this CustomField
is set to “Ported and Routed”, I want the call assigned to myself.
This CustomField appears to be Field 15, given that the URL ends in
"Modify.html?id=15".

I’ve created a scrip for my test queue with the following settings:

Description: assign owner on port completion
Condition: user defined
Action: user defined
Template: Global template: Transaction
Stage: TransactionCreate

My custom condition is taken straight from the example.

unless (
( $self->TransactionObj->Type eq “CustomField”
&& $self->TransactionObj->Field == 15 )
|| $self->TransactionObj->Type eq “Create”
) {
return 0;
}

return 0 unless $self->TicketObj->FirstCustomFieldValue(‘Port Completion’)
=~ /Ported and Routed/i;

1;

The Custom action preparation code is:

$self->TicketObj->SetOwner(‘Michael W Lucas’);
return 1;

There is no cleanup code. This looks like it should be perfectly
straightforward.

Any suggestions, folks? Is there any place I can trace what’s
happening in the scrip, or what RT is doing when this is run?

Thanks,
==ml

Michael W. Lucas mwlucas@BlackHelicopters.org
http://www.MichaelWLucas.com/, http://blather.MichaelWLucas.com/
New book: Network Flow Analysis
pre-order now! http://www.networkflowanalysis.com/

Forgot to say, I’m running RT 3.8.6 on FreeBSD 8.

Thanks,
==mlOn Tue, Jun 15, 2010 at 03:05:56PM -0400, Michael W. Lucas wrote:

Hi,

I’m trying to write a trigger for a particular custom field, as
described at
http://wiki.bestpractical.com/view/OnCustomFieldValueChange, and
apparently I don’t understand something. I’d appreciate any
enlightenment anyone can offer, pointers to docs I should read, etc.

I have a CustomField called “Port Completion”. When this CustomField
is set to “Ported and Routed”, I want the call assigned to myself.
This CustomField appears to be Field 15, given that the URL ends in
"Modify.html?id=15".

I’ve created a scrip for my test queue with the following settings:

Description: assign owner on port completion
Condition: user defined
Action: user defined
Template: Global template: Transaction
Stage: TransactionCreate

My custom condition is taken straight from the example.

unless (
( $self->TransactionObj->Type eq “CustomField”
&& $self->TransactionObj->Field == 15 )
|| $self->TransactionObj->Type eq “Create”
) {
return 0;
}

return 0 unless $self->TicketObj->FirstCustomFieldValue(‘Port Completion’)
=~ /Ported and Routed/i;

1;

The Custom action preparation code is:

$self->TicketObj->SetOwner(‘Michael W Lucas’);
return 1;

There is no cleanup code. This looks like it should be perfectly
straightforward.

Any suggestions, folks? Is there any place I can trace what’s
happening in the scrip, or what RT is doing when this is run?

Thanks,
==ml


Michael W. Lucas mwlucas@BlackHelicopters.org
http://www.MichaelWLucas.com/, http://blather.MichaelWLucas.com/
New book: Network Flow Analysis
pre-order now! http://www.networkflowanalysis.com/

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

Michael W. Lucas mwlucas@BlackHelicopters.org
http://www.MichaelWLucas.com/, http://blather.MichaelWLucas.com/
New book: Network Flow Analysis
pre-order now! http://www.networkflowanalysis.com/

Michael,

Try this:

Name: Set Owner on CF
Condition: User-Defined
Action: User-Defined
Template: Blank
Stage: TransactionBatch

Custom Condition:
#determine if correct CF & value changed

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;

if ($trans->Type eq ‘CustomField’)
{my $cf = new RT::CustomField($RT::SystemUser);
$cf->LoadByName(Queue => $ticket->QueueObj->id,
Name => “Port Completion”);
return 0 unless $cf->id;
if ($trans->Field == $cf->id &&
$trans->NewValue eq “Ported and Routed”)
{
return 1;
}
}

return 0;

Custom Prep Code:

set Ticket Owner ID

my $ticket = $self->TicketObj;
my $ownerid = my id

$ticket->SetOwner($ownerid);
return 1;

Custom Cleanup Code:

return 1;

Hope this helps

Kenn
LBNLOn Tue, Jun 15, 2010 at 12:05 PM, Michael W. Lucas < mwlucas@blackhelicopters.org> wrote:

Hi,

I’m trying to write a trigger for a particular custom field, as
described at
http://wiki.bestpractical.com/view/OnCustomFieldValueChange, and
apparently I don’t understand something. I’d appreciate any
enlightenment anyone can offer, pointers to docs I should read, etc.

I have a CustomField called “Port Completion”. When this CustomField
is set to “Ported and Routed”, I want the call assigned to myself.
This CustomField appears to be Field 15, given that the URL ends in
"Modify.html?id=15".

I’ve created a scrip for my test queue with the following settings:

Description: assign owner on port completion
Condition: user defined
Action: user defined
Template: Global template: Transaction
Stage: TransactionCreate

My custom condition is taken straight from the example.

unless (
( $self->TransactionObj->Type eq “CustomField”
&& $self->TransactionObj->Field == 15 )
|| $self->TransactionObj->Type eq “Create”
) {
return 0;
}

return 0 unless $self->TicketObj->FirstCustomFieldValue(‘Port Completion’)
=~ /Ported and Routed/i;

1;

The Custom action preparation code is:

$self->TicketObj->SetOwner(‘Michael W Lucas’);
return 1;

There is no cleanup code. This looks like it should be perfectly
straightforward.

Any suggestions, folks? Is there any place I can trace what’s
happening in the scrip, or what RT is doing when this is run?

Thanks,
==ml


Michael W. Lucas mwlucas@BlackHelicopters.org
http://www.MichaelWLucas.com/, http://blather.MichaelWLucas.com/
New book: Network Flow Analysis
pre-order now! http://www.networkflowanalysis.com/

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

That does it, thank you very much!

For the archives: I had to replace “my id” in the prep code with
"mwlucas"; , including the quotes and the semicolon.

==mlOn Tue, Jun 15, 2010 at 12:35:19PM -0700, Kenneth Crocker wrote:

Michael,

Try this:

Name: Set Owner on CF
Condition: User-Defined
Action: User-Defined
Template: Blank
Stage: TransactionBatch

Custom Condition:
#determine if correct CF & value changed

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;

if ($trans->Type eq ‘CustomField’)
{my $cf = new RT::CustomField($RT::SystemUser);
$cf->LoadByName(Queue => $ticket->QueueObj->id,
Name => “Port Completion”);
return 0 unless $cf->id;
if ($trans->Field == $cf->id &&
$trans->NewValue eq “Ported and Routed”)
{
return 1;
}
}

return 0;

Custom Prep Code:

set Ticket Owner ID

my $ticket = $self->TicketObj;
my $ownerid = my id

$ticket->SetOwner($ownerid);
return 1;

Custom Cleanup Code:

return 1;

Hope this helps

Kenn
LBNL

On Tue, Jun 15, 2010 at 12:05 PM, Michael W. Lucas < mwlucas@blackhelicopters.org> wrote:

Hi,

I’m trying to write a trigger for a particular custom field, as
described at
http://wiki.bestpractical.com/view/OnCustomFieldValueChange, and
apparently I don’t understand something. I’d appreciate any
enlightenment anyone can offer, pointers to docs I should read, etc.

I have a CustomField called “Port Completion”. When this CustomField
is set to “Ported and Routed”, I want the call assigned to myself.
This CustomField appears to be Field 15, given that the URL ends in
"Modify.html?id=15".

I’ve created a scrip for my test queue with the following settings:

Description: assign owner on port completion
Condition: user defined
Action: user defined
Template: Global template: Transaction
Stage: TransactionCreate

My custom condition is taken straight from the example.

unless (
( $self->TransactionObj->Type eq “CustomField”
&& $self->TransactionObj->Field == 15 )
|| $self->TransactionObj->Type eq “Create”
) {
return 0;
}

return 0 unless $self->TicketObj->FirstCustomFieldValue(‘Port Completion’)
=~ /Ported and Routed/i;

1;

The Custom action preparation code is:

$self->TicketObj->SetOwner(‘Michael W Lucas’);
return 1;

There is no cleanup code. This looks like it should be perfectly
straightforward.

Any suggestions, folks? Is there any place I can trace what’s
happening in the scrip, or what RT is doing when this is run?

Thanks,
==ml


Michael W. Lucas mwlucas@BlackHelicopters.org
http://www.MichaelWLucas.com/, http://blather.MichaelWLucas.com/
New book: Network Flow Analysis
pre-order now! http://www.networkflowanalysis.com/

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

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

Michael W. Lucas mwlucas@BlackHelicopters.org
http://www.MichaelWLucas.com/, http://blather.MichaelWLucas.com/
New book: Network Flow Analysis
pre-order now! http://www.networkflowanalysis.com/