I just can't figure out how to get the values from mycustom fields!

Please - Any clues?
It would be most appreciated.

Med venlig hilsen / Best regards
Brian Kjelin Olsen
Schilling A/S
-----Oprindelig meddelelse-----Fra: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] På vegne af Brian Kjelin Olsen
Sendt: 4. marts 2007 10:26
Til: rt-users@lists.bestpractical.com
Emne: [rt-users] I just can’t figure out how to get the values from mycustom fields!

Hi everyone

I just can’t figure how to get the values of custom fields on ticket transactions from scrip.
As an example I have made this small scrip where I print the field names and then try to get the values from those fields.

— Scrip example —
my $k=“”; my $v=“”;
$RT::Logger->debug(“Get names of transaction Custom fields from the ticket object”);
if (my $TCFs = $self->TicketObj->TransactionCustomFields()) {
while (my $CF = $TCFs->Next()) {
$RT::Logger->debug(“Get values from transaction custom field '” . $CF->Name . “’ from the transaction object”);
my %values = $self->TransactionObj->CustomFieldValues($CF->Name);
while (($k,$v) = each %values) {
$RT::Logger->debug(“$k => $v”);
}
$RT::Logger->debug(“End of getting values from transaction custom field '” . $CF->Name . “’ from the transaction object”);
}
}
$RT::Logger->debug(“End of getting names of transaction Custom fields from the ticket object”);

As a result (See log below) I seems to get two value hashes, but without any values?!?!
(And - “Yes: I do remember to add some values to the two fields while making the test transaction” :slight_smile:

PS This is my first Perl and RT programming, so I guess that this could be the reason :slight_smile:

----- Log file ------
[Sat Mar 3 20:24:08 2007] [debug]: Get names of transaction Custom fields from the ticket object ((eval 429):16)
[Sat Mar 3 20:24:08 2007] [debug]: Get values from transaction custom field ‘Service type’ from the transaction object ((eval 429):19)
[Sat Mar 3 20:24:08 2007] [debug]: RT::ObjectCustomFieldValues=HASH(0xac022b4) => ((eval 429):22)
[Sat Mar 3 20:24:08 2007] [debug]: End of getting values from transaction custom field ‘Service type’ from the transaction object ((eval 429):24)
[Sat Mar 3 20:24:08 2007] [debug]: Get values from transaction custom field ‘Service text’ from the transaction object ((eval 429):19)
[Sat Mar 3 20:24:08 2007] [debug]: RT::ObjectCustomFieldValues=HASH(0x9aa45f4) => ((eval 429):22)
[Sat Mar 3 20:24:08 2007] [debug]: End of getting values from transaction custom field ‘Service text’ from the transaction object ((eval 429):24)
[Sat Mar 3 20:24:08 2007] [debug]: End of getting names of transaction Custom fields from the ticket object ((eval 429):27)

Med venlig hilsen / Best regards
Brian Kjelin Olsen
Systemkonsulent

Schilling A/S
Baldersbækvej 24-26
DK-2635 Ishøj
Tel: +45 70 27 99 00
Fax: +45 70 27 99 10
bko@schilling.dk
www.schilling.dk

http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

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

I just can’t figure how to get the values of custom fields on ticket transactions from scrip.

Here’s what I’ve done in a Condition’s IsApplicable() sub:

my($CFNAME) = 'Severity';

my($q) = $self->TicketObj->QueueObj;
my($cf) = new RT::CustomField $q->CurrentUser;

$cf->LoadByNameAndQueue(Name => $CFNAME, Queue => $q->id);
$cf->LoadByNameAndQueue(Name => $CFNAME, Queue => 0) unless $cf->id;
unless ($cf->id) {
	$RT::Logger->warning("Custom field '$CFNAME' isn't global or defined 

for queue ‘" . $q->Name . "’");
return undef;
}

return ! $self->TicketObj->FirstCustomFieldValue($cf->id);

Hope that helps!

Regards,

joe

| Joe Casadonte | joe.casadonte@oracle.com |
|~| |
| Oracle Transportation Management | 1016 West Ninth Avenue |
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Suite 300 |
| 610-491-3315 | King of Prussia, PA 19406 |

Brian,

Are you trying to get values from existing ticket custom fields? Ticket 

transaction custom fields are different from ticket custom fields. If
you are trying to get values from existing tickets, then the transaction
custom fields may very well have no values any longer.

Kenn
LBNL

Brian Kjelin Olsen wrote:

At Monday 3/5/2007 03:08 AM, Brian Kjelin Olsen wrote:

Please - Any clues?
It would be most appreciated.

Med venlig hilsen / Best regards
Brian Kjelin Olsen
Schilling A/S
-----Oprindelig meddelelse-----
Fra: rt-users-bounces@lists.bestpractical.com
[mailto:rt-users-bounces@lists.bestpractical.com]
På vegne af Brian Kjelin Olsen
Sendt: 4. marts 2007 10:26
Til: rt-users@lists.bestpractical.com
Emne: [rt-users] I just can’t figure out how to
get the values from mycustom fields!

Hi everyone

I just can’t figure how to get the values of
custom fields on ticket transactions from scrip.
As an example I have made this small scrip where
I print the field names and then try to get the values from those fields.

— Scrip example —
my $k=“”; my $v=“”;
$RT::Logger->debug(“Get names of transaction
Custom fields from the ticket object”);
if (my $TCFs = $self->TicketObj->TransactionCustomFields()) {
while (my $CF = $TCFs->Next()) {
$RT::Logger->debug(“Get values from
transaction custom field '” . $CF->Name . “’ from the transaction object”);
my %values = $self->TransactionObj->CustomFieldValues($CF->Name);
while (($k,$v) = each %values) {
$RT::Logger->debug(“$k => $v”);
}
$RT::Logger->debug(“End of getting
values from transaction custom field '” .
$CF->Name . “’ from the transaction object”);
}
}
$RT::Logger->debug(“End of getting names of
transaction Custom fields from the ticket object”);

It looks like you’re pretty close -

$self->TransactionObj->CustomFieldValues($CF->Name)
will give you an ObjectCustomFieldValues
collection object - each member of the collection
is an ObjectCustomFieldValue object. You can
iterate over the collection and see the values something like this:

my $values = $self->TransactionObj->CustomFieldValues($CF->Name);
while (my $CFV = $values->Next() ) {
$RT::Logger->debug($CFV->Content);
}

Steve