Custom Condition based on Transaction Custom Field value

Hi!

Is $subject possible? In the last six hours i tried to do it, without
any luck.( I don’t think i did it the right way…) If somebody did it
(successfully :)), please tell me how! Oh! RT 3.4.1
I need some sleep now…

Thanks for any advice!

Peter

Hi!

Is $subject possible? In the last six hours i tried to do it, without
any luck.( I don’t think i did it the right way…) If somebody did it
(successfully :)), please tell me how! Oh! RT 3.4.1
I need some sleep now…

Thanks for any advice!

Please explain the problem clearly and what you’re trying to do. What
does “Custom Condition based on Transaction Custom Field value” have
to do with “$subject”?

Andy Harrison

Andy Harrison �rta:>On Sat, 5 Mar 2005 03:45:33 +0100, P�ter M�rton marton.peter@gmail.com wrote:

Please explain the problem clearly and what you’re trying to do. What
does “Custom Condition based on Transaction Custom Field value” have
to do with “$subject”?

Sorry, i was very tired.
I was able to make a scrip with a custom condition that checks the value
of a custom field:

(from the wiki:)
return undef unless ($self->TicketObj->FirstCustomFieldValue(‘Name_of_your_Custom_Field’) =~ /matchtext/i);
return 1;

but (my problem is that) it checks only for “CustomField for queue”, and i want to check a “Transaction Custom Field” value,
and if i fetch a TransactionObj (with $self->TransactionObj) it has only a CustomFieldValues. Hmmm…
So i tried this:

my $Ticket = $self->TransactionObj;
my $CustomFieldValues=$Ticket->CustomFieldValues;
while (my $CustomFieldValue = $CustomFieldValues->Next) {
$RT::Logger->error( ".CFV. ".$CustomFieldValue->Content );
}

But it logs nothing.

What should i do?

Andy Harrison írta:

Please explain the problem clearly and what you’re trying to do. What
does “Custom Condition based on Transaction Custom Field value” have
to do with “$subject”?

Sorry, i was very tired.
I was able to make a scrip with a custom condition that checks the value
of a custom field:

(from the wiki:)
return undef unless ($self->TicketObj->FirstCustomFieldValue(‘Name_of_your_Custom_Field’) =~ /matchtext/i);
return 1;

but (my problem is that) it checks only for “CustomField for queue”, and i want to check a “Transaction Custom Field” value,
and if i fetch a TransactionObj (with $self->TransactionObj) it has only a CustomFieldValues. Hmmm…
So i tried this:

my $Ticket = $self->TransactionObj;
my $CustomFieldValues=$Ticket->CustomFieldValues;
while (my $CustomFieldValue = $CustomFieldValues->Next) {
$RT::Logger->error( ".CFV. ".$CustomFieldValue->Content );
}

But it logs nothing.

$self->TicketObj->FirstCustomFieldValue(‘yourfield’) will return the
contents of a custom field from the current ticket. Individual
transactions do not have custom fields.

What are you trying to do?

Andy Harrison

$self->TicketObj->FirstCustomFieldValue(‘yourfield’) will return the

I tried this, but i get “nix” as value:
$RT::Logger->error( “.iIi.” .$self->TicketObj->FirstCustomFieldValue(‘nyomi’));
Mar 7 12:00:10 linux RT: .iIi.nix ((eval 980):1)

contents of a custom field from the current ticket. Individual
transactions do not have custom fields.

If i go to configuration, custom fields, there are two sections:
“Custom Fields for Tickets” and “Custom Fields for Ticket
Transactions” and the latter is what i need.

What are you trying to do?

I try to make a scrip that makes something (generates a file on the
server itself) based on the decision of the Comment maker. I thought
it would be the simplest way to have a custom field, what could be
filled out (or selected) at the time of making the comment. And bingo,
the “Custom Fields for Ticket Transactions” is exactly what i need
because it remains in its original state (undef) after the
transaction, and can be defined on the “Update ticket” page. But i
can’t find a way to read that Custom Field. :frowning:

At Sunday 3/6/2005 08:11 PM, Andy Harrison wrote:

but (my problem is that) it checks only for “CustomField for queue”,
and i want to check a “Transaction Custom Field” value,
and if i fetch a TransactionObj (with $self->TransactionObj) it has
only a CustomFieldValues. Hmmm…
So i tried this:

my $Ticket = $self->TransactionObj;
my $CustomFieldValues=$Ticket->CustomFieldValues;
while (my $CustomFieldValue = $CustomFieldValues->Next) {
$RT::Logger->error( ".CFV. ".$CustomFieldValue->Content );
}

But it logs nothing.

Is your RT configured to log errors? If so, that would indicate there are
no values for the CF for the transaction. Have you played around with perl
scripts that access the RT API? They’re great for pulling out bits of code
like this and using the perl debugger to step through and get a better idea
of what’s going on.

Individual transactions do not have custom fields.

What are you trying to do?

Transaction custom fields are a neat, newer feature. I think they first
appeared in the 3.3 series.

Steve

Stephen Turner �rta:

Is your RT configured to log errors? If so, that would indicate there
are no values for the CF for the transaction. Have you played around
with perl scripts that access the RT API? They’re great for pulling
out bits of code like this and using the perl debugger to step through
and get a better idea of what’s going on.

Yes, it’s logs errors, and i wrote something in the CF.
My scrip condition:

my $Ticket = $self->TransactionObj;
my $CustomFieldValues=$Ticket->CustomFieldValues;
$RT::Logger->error( “Warning!Self destruct sequence has been initiated!”);
$RT::Logger->error( “Warp core overload in 4 minutes 55 seconds.” );
while (my $CustomFieldValue = $CustomFieldValues->Next) {
$RT::Logger->error( ".CFV. ".$CustomFieldValue->Content );
};
$RT::Logger->error( “There will be no further audio warnings!” );
return (1);

And the log for a transaction:

Mar 8 21:31:55 linux RT: About to think about scrips for transaction #1409
Mar 8 21:31:55 linux RT: About to prepare scrips for transaction #1409
Mar 8 21:31:55 linux RT: Found 5 scrips
Mar 8 21:31:56 linux RT: Warning!Self destruct sequence has been
initiated! ((eval 1201):3)
Mar 8 21:31:56 linux RT: Warp core overload in 4 minutes 55 seconds.
((eval 1201):4)
Mar 8 21:31:56 linux RT: There will be no further audio warnings!
((eval 1201):8)
Mar 8 21:31:56 linux RT: About to commit scrips for transaction #1409
Mar 8 21:31:56 linux RT:
rt-3.4.1-98-1409-8.16.6756791385311@cc.mailmax.hu #98/1409 - Scrip 8
(/opt/rt3/lib/RT/Action/SendEmail.pm:235)
Mar 8 21:31:56 linux RT:
rt-3.4.1-98-1409-8.16.6756791385311@cc.mailmax.hu No recipients found.
Not sending. (/opt/rt3/lib/RT/Action/SendEmail.pm:247)
Mar 8 21:31:56 linux RT:
rt-3.4.1-98-1409-9.8.78181131431681@cc.mailmax.hu #98/1409 - Scrip 9
(/opt/rt3/lib/RT/Action/SendEmail.pm:235)
Mar 8 21:31:59 linux RT: About to think about scrips for transaction #1410
Mar 8 21:31:59 linux RT:
rt-3.4.1-98-1409-9.8.78181131431681@cc.mailmax.hu sent To: Cc:
marton.peter@gmail.com Bcc: (/opt/rt3/lib/RT/Action/SendEmail.pm:295)

In my mind it means that the first call for
$self->TransactionObj->$CustomFieldValues->Next returns undef as it
would no Transaction CF be there. Is it so?

I made a small script, but it gives an error… :frowning: Should i initialize
something? (self destruct maybe? :))

#!/usr/bin/perl -I/opt/rt3/lib
use RT;
RT::LoadConfig;
RT::Init;
my $u = RT::User->new($RT::SystemUser);
$u->Load(“root”);
my $t = RT::Ticket->new($u);
$t->Load(“98”);
my $trs = $t->Transactions;

Mar 9 00:11:46 linux RT: at /opt/rt3/lib/RT/Ticket_Overlay.pm line
3564 RT::ticket::HasRight(‘RT::Ticket=HASH(0x8ec30d4)’,
‘Principal’, 0, ‘No object mapping for field’, ‘Right’, ‘ShowTicket’)
called at /opt/rt3/lib/RT/Ticket_Overlay.pm line 3532
RT::ticket::CurrentUserHasRight(‘RT::Ticket=HASH(0x8ec30d4)’,
‘ShowTicket’) called at /opt/rt3/lib/RT/Ticket_Overlay.pm line
3595 RT::ticket::Transactions(‘RT::Ticket=HASH(0x8ec30d4)’) called
at ./rtx line 9 (/opt/rt3/lib/RT.pm:277)
Mar 9 00:11:46 linux RT: Principal attrib undefined for
Ticket::HasRight (/opt/rt3/lib/RT/Ticket_Overlay.pm:3565)

Thanks for the help!

At Wednesday 3/9/2005 10:17 AM, MP wrote:

Stephen Turner írta:

In my mind it means that the first call for
$self->TransactionObj->$CustomFieldValues->Next returns undef as it would
no Transaction CF be there. Is it so?

Yes (I think!). In other words there are no values for the CF.

I made a small script, but it gives an error… :frowning: Should i initialize
something? (self destruct maybe? :))

#!/usr/bin/perl -I/opt/rt3/lib
use RT;
RT::LoadConfig;
RT::Init;
my $u = RT::User->new($RT::SystemUser);
$u->Load(“root”);
my $t = RT::Ticket->new($u);
$t->Load(“98”);
my $trs = $t->Transactions;

Mar 9 00:11:46 linux RT: at /opt/rt3/lib/RT/Ticket_Overlay.pm line
3564 RT::ticket::HasRight(‘RT::Ticket=HASH(0x8ec30d4)’, ‘Principal’,
0, ‘No object mapping for field’, ‘Right’, ‘ShowTicket’) called at
/opt/rt3/lib/RT/Ticket_Overlay.pm line 3532
RT::ticket::CurrentUserHasRight(‘RT::Ticket=HASH(0x8ec30d4)’,
‘ShowTicket’) called at /opt/rt3/lib/RT/Ticket_Overlay.pm line
3595 RT::ticket::Transactions(‘RT::Ticket=HASH(0x8ec30d4)’) called
at ./rtx line 9 (/opt/rt3/lib/RT.pm:277)
Mar 9 00:11:46 linux RT: Principal attrib undefined for Ticket::HasRight
(/opt/rt3/lib/RT/Ticket_Overlay.pm:3565)

Try passing $RT::SystemUser (instead of $u ) to RT::Ticket->new.

Steve

$self->TicketObj->FirstCustomFieldValue(‘yourfield’) will return the
contents of a custom field from the current ticket. Individual
transactions do not have custom fields.

As of 3.4 Transactions can have custom fields.

Hi Steve!

Thanks for the help, it was what i needed!
I found out the obvious. In Transaction_Overlay.pm :

sub CustomFieldValues {
    my $self  = shift;
    my $field = shift;

(…)
return $self->SUPER::CustomFieldValues($field);
<<<
Without a $field value it returns nothing! So i gave him a
CustomField->Name:

    my $CustomFieldValues=$tr->CustomFieldValues("nyomi");

<<<
And it worked! :smiley:
But if i do it in a scrip condition it gives me nothing:

my $Tr = $self->TransactionObj;
my $CustomFieldValues=$Tr->CustomFieldValues(“nyomi”);
$RT::Logger->error( “Warning!Self destruct sequence has been initiated!”);
$RT::Logger->error( “Warp core overload in 4 minutes 55 seconds.” );
while (my $CustomFieldValue = $CustomFieldValues->Next) {
$RT::Logger->error( ".CFV. ".$CustomFieldValue->Content );
};
$RT::Logger->error( “There will be no further audio warnings!” );
return (1);
<<<
Mar 9 21:13:39 linux RT: Warning!Self destruct sequence has been
initiated! ((eval 1365):3)
Mar 9 21:13:39 linux RT: Warp core overload in 4 minutes 55 seconds.
((eval 1365):4)
Mar 9 21:13:39 linux RT: There will be no further audio warnings!
((eval 1365):8)

I also tried to extract the transaction from the TicketObj… but no luck:

my $CFV;
my $t = $self->TicketObj;
$RT::Logger->error( “Req=”.$t->RequestorAddresses);
my $trs = $t->Transactions;
while (my $tr = $trs->Next)
{
my $CustomFieldValues = $tr->CustomFieldValues(“nyomi”);
my $CustomFieldValue = $CustomFieldValues->Next;
my $CFV = $CustomFieldValue->Content;
};
$RT::Logger->error( “CFV=”.$CFV );
return(1);
<<<
Mar 9 21:58:54 linux RT: About to think about scrips for transaction #1443
Mar 9 21:58:54 linux RT: About to prepare scrips for transaction #1443
Mar 9 21:58:55 linux RT: Found 5 scrips
Mar 9 21:58:55 linux RT: Req=root@localhost ((eval 1465):3)
Mar 9 21:58:55 linux RT: Scrip 17 IsApplicable failed: Can’t call
method “Content” on an undefined value at (eval 1465) line 9. Stack:
[(eval 1465):9] [/opt/rt3/lib/RT/ScripCondition_Overlay.pm:219]
[/opt/rt3/lib/RT/Scrip_Overlay.pm:438]
[/opt/rt3/lib/RT/Scrips_Overlay.pm:228]
[/opt/rt3/lib/RT/Transaction_Overlay.pm:160]
[/opt/rt3/lib/RT/Record.pm:1373]
[/opt/rt3/lib/RT/Ticket_Overlay.pm:2369]
[/opt/rt3/lib/RT/Ticket_Overlay.pm:2255]
[/opt/rt3/lib/RT/Interface/Web.pm:469]
[/opt/rt3/share/html/Ticket/Display.html:135]
[/opt/rt3/share/html/Ticket/Update.html:211]
[/opt/rt3/share/html/autohandler:215]
(/opt/rt3/lib/RT/Condition/UserDefined.pm:67)
Mar 9 21:58:56 linux RT: About to commit scrips for transaction #1443

So we are where we started… :frowning: $CustomFieldValues returns undef…

I paste here the only working example… i don’t understand the
difference between the two Ticket objects… One in a perl script…
another in a scrip?
[I thought it was a seecustomfield right problem, so i added this right to root - above of superuser :slight_smile: but it didn’t help…]

#!/usr/bin/perl -I/opt/rt3/lib
use RT;
RT::LoadConfig;
RT::Init;
my $u = RT::User->new($RT::SystemUser);
$u->Load(“root”);
my $t = RT::Ticket->new($RT::SystemUser);
$t->Load(“98”);
my $trs = $t->Transactions;

while (my $tr = $trs->Next)
{
print $tr->Subject;
print “\n”;
my $CustomFieldValues=$tr->CustomFieldValues(“nyomi”);
while (my $CustomFieldValue = $CustomFieldValues->Next)
{
print “\t”.$CustomFieldValue->Content;
print “\n”;
};
};
<<<

Stephen Turner �rta: