Getting the values of custom fields

I’m using 3.4.6 and have a ticket that has some CustomField values.

I’m having a horrible time pulling these entries.

I’m doing this via the web and User Defined scripts. For testing I’m
saying On status change run this action.

I’ve been messing with Ticket_Overlay CustomValues, CustomValues,
TicketTransactions…

Now I’m wondering if the data is just for the status change transaction
and the values in the custom fields are not even in the $self data.

Does this sound right?

Doing this via sql sounds much simpler.

Anthony,

What are you using the data for? We pull some custom data to use on our 

“Resolve” template. It is as follows:

RT-Attach-Message: yes

Your request has been resolved. If you have any further questions or
concerns,
please respond to this message.

To view ticket information, enter URL:
{$RT::WebURL}Ticket/Display.html?id={$Ticket->id} .

Ticket Description:
{
my $Resolution_Description;
$Resolution_Description =
$Ticket->FirstCustomFieldValue(‘Description’);
return $Resolution_Description;
}

Resolution:
{
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;
  }

  return $Resolution_Comment;

}

Hope this helps.

Kenn
LBNL

anthony wrote:

I’m doing this via script action.
FirstCustom… is in Record which is not part of the $self.

I get TicketObj, TransactionObj ( which does not seems to work )

I’m tried to use CustomFieldValues but I get stuck after that.

Searches through the archive seem to say NO ONE has done this successfully.

Kenneth Crocker wrote:

Anthony,

We use the following code to send a notification, via a scrip custom 

condition, when the owner changes, providing the owner isn’t “nobody”:

return ( $TicketObj->OwnerObj->Name() ne ‘Nobody’ );

Maybe this will help you build your code in a scrip.

Kenn
LBNL

anthony wrote:

Where are you doing this the webui? I’m using
configure-queue-script-new script-condition: on status change, action:
user defined.

In the preparation section I put
$RT::Logger->debug(“SCRIPT: $TicketObj->OwnerObj->Name\n”);

It should be $self->TicketObj

I then ran it again and got
SCRIPT:
RT::Action::UserDefined=HASH(0xcc9e670)->TicketObj->OwnerObj->Name()

The perldoc Ticket_Overlay has CustomFieldValues which sends you to
ObjectCustomFieldValues_Overlay which has

LimitToCustomField FIELD

   Limits the returned set to values for the custom field with Id FIELD

   LimitToTicket TICKETID

   Limits the returned set to values for the ticket with Id TICKETID

   Returns true if this CustomFieldValues collection has an entry with
   content that eq VALUE

Neither of which return anything.

Kenneth Crocker wrote:

Where are you doing this the webui?

The following worked for me in 3.6.3 (Note: this is NOT through the
WebUI – not sure if it will help you or not):

sub IsApplicable
{
my($self) = shift;

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);

}

and:

sub Prepare
{
my($self) = shift;

my($CFNAME) = 'Severity';
my($CFDEFVAL) = 'Medium';

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;

my($rc, $msg) = $self->TicketObj->AddCustomFieldValue(Field => $CFNAME,
													  Value => $CFDEFVAL,
													  RecordTransaction => 1);

unless ($rc) {
	$RT::Logger->warning("Could not set '$CFNAME' to '$CFDEFVAL': $msg");
	return undef;
}

return 1;

}

Regards,

joe
Joe Casadonte
joe.casadonte@oracle.com

Kenneth,
Thanks for sticking with me. I’m tailing the logs and see errors when
ever I put something invalid in the Custom action section.

If I put something (debug) into the custom condition It doesn't get any

output. I have user defined only for Action.

Right now I'm trying to add a package to the RT::Action section.

Kenneth Crocker wrote:

This is working but unreliable.

Copied RT/Action/Autoreply.pm to PullCode.pm

Change package to RT::Action::PullCode

In script

Condition: On Status Change
Action: Pull Code
Template: Status Change

Now sometimes it works and I get the email. Other times I get

[Wed Feb 14 03:16:38 2007] [error]: Scrip Prepare 32 died. - Can’t
locate object method “new” via package “RT::Action::PullCode” at
/opt/rt3/lib/RT/ScripAction_Overlay.pm line 178.

Stack:
[/opt/rt3/lib/RT/ScripAction_Overlay.pm:178]
[/opt/rt3/lib/RT/Scrip_Overlay.pm:473]
[/opt/rt3/lib/RT/Scrips_Overlay.pm:236]
[/opt/rt3/lib/RT/Transaction_Overlay.pm:168]
[/opt/rt3/lib/RT/Record.pm:1441]
[/opt/rt3/lib/RT/Ticket_Overlay.pm:3478]
[/opt/rt3/lib/RT/Ticket_Overlay.pm:3209]
[/opt/rt3/lib/RT/Record.pm:931]
[/opt/rt3/lib/RT/Interface/Web.pm:975]
[/opt/rt3/lib/RT/Interface/Web.pm:1089]
[/opt/rt3/share/html/Ticket/ModifyAll.html:178]
[/opt/rt3/share/html/autohandler:215]
(/opt/rt3/lib/RT/Scrip_Overlay.pm:481)

anthony wrote:

I’m doing this via script action.
FirstCustom… is in Record which is not part of the $self.

I get TicketObj, TransactionObj ( which does not seems to work )

I’m tried to use CustomFieldValues but I get stuck after that.

Searches through the archive seem to say NO ONE has done this successfully.
This is part of our script which ties timeworked to an asset which hold
how many hours a client has left on his contract.
use Data::Dumper;

start to define a couple of useful objects.

my $TicketObj = $self->TicketObj;
my $QueueObj = $self->TicketObj->QueueObj;
my $TransObj = $self->TransactionObj;
my $TemplObj = $self->TemplateObj;

$RT::Logger->debug( Dumper($TemplObj) );

my $qname = $self->TicketObj->QueueObj->Name;
my $cfname = ‘Strippenkaart’;
my $timetaken;
my $abstimetaken_new;
my $abstimetaken_old;
my $assettype;

$RT::Logger->debug("$qname");

$RT::Logger->debug("$timetaken");

my $ttype = $TransObj->Type;
my $tfield = $TransObj->Field;

$RT::Logger->debug($ttype);

$RT::Logger->debug($tfield);

make a new CFObj and fill it

my $CFObj = RT::CustomField->new( $QueueObj->CurrentUser );
$CFObj->LoadByNameAndQueue( Name => $cfname, Queue => $QueueObj->id );
unless ( $CFObj->id ) {
$CFObj->LoadByNameAndQueue( Name => $cfname, Queue => 0 );
unless ( $CFObj->id ) {
$RT::Logger->debug(
“custom field ‘$cfname’ isn’t global or defined for
queue '”
. $QueueObj->Name
. “’” );
return undef;
}
}

get the first CFValue

my $cfvalue = $self->TicketObj->FirstCustomFieldValue( $CFObj->id );
$RT::Logger->debug("$cfvalue");

then create an empty AssetObj with the current user

my $AssetObj = RTx::AssetTracker::Asset->new( $QueueObj->CurrentUser );

get its values given the convention AssetName=QueueName+CFValue

check if status == production

further Name is unique in the DB, is possible to change via

AT_SiteConfig.pm

still check if AssetType==Strippenkaart

$AssetObj->Load($qname.$cfvalue);
$assettype=$AssetObj->TypeObj->Name;
if ( $assettype ne ‘Strippenkaart’ ) {
$RT::Logger->debug(“No Asset of type Strippenkaart”);
return undef;
}

my $desc = $AssetObj->Description;
my $status = $AssetObj->Status;
if ( $status ne ‘production’ ) { return undef; }

$RT::Logger->debug("$desc");

get the CustomFields (cnt>0)

my $AssetCFObj = $AssetObj->CustomFields();
my $cfcount = $AssetCFObj->Count;
if ( $cfcount == 0 ) { return undef; }

process the CF’s

Does this make sense?

Joop

Joop,
Thanks that really helps. I’m able to pull the first value from my
custom field now.

However the field I have is a multi value on and I'm not trying to use

CustomFiledValues which returns a ObjectCustomFieldValues Object.

I don’t really know what to do with that. I’ve tried a whole bunch of
things but I’m just guessing.

The ObjectCustomFiled Object has this as a Hash

[Wed Feb 14 16:55:32 2007] [debug]: _open_parens - HASH(0xa414aec)
((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: alias_count - 0 ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: where_clause - ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: order_by - ARRAY(0xa523034) ((eval
948):50)
[Wed Feb 14 16:55:32 2007] [debug]: table - ObjectCustomFieldValues
((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: tables - ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: is_limited - 1 ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: order - ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: user -
RT::CurrentUser=HASH(0xa5f17c8) ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: limit_clause - ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: DBIxHandle -
RT::Handle=HASH(0x9a42c6c) ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: restrictions - HASH(0xa61436c)
((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: primary_key - id ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: auxillary_tables - ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: must_redo_search - 1 ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: itemscount - 0 ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: show_rows - 0 ((eval 948):50)
[Wed Feb 14 16:55:32 2007] [debug]: aliases - ARRAY(0xa42ceb4) ((eval
948):50)
[Wed Feb 14 16:55:32 2007] [debug]: first_row - 0 ((eval 948):50)

Thanks.

Joop wrote: