[Rt-devel] Problem with DefaultCustomFieldValue

Andy Harrison aharrison at gmail.com
Wed Mar 2 12:09:15 EST 2005


On Tue, 1 Mar 2005 11:37:41 +0100, Juan Ramón Alfageme Mata
<JRamon.Alfageme at alhambra-eidos.com> wrote:
> 
> Still not working, I tried following code as global script:
> 
> Condition: On Transaction
> Action: User Defined
> Template:   Global template: Blank
> Stage: TransactionCreate
> Custom condition:
> Custom action preparation code:
> my $CFName = 'Provider';
> my $DefaultValue = 'BT';
> 
> my $CustomFieldsObj = $self->TicketObj->QueueObj->CustomFields();
> while ( my $CustomFieldObj = $CustomFieldsObj->Next() ) {
> next unless ( $CustomFieldObj->Name = $CFName ) {
> my( $st, $msg ) = $self->TicketObj->AddCustomFieldValue( Field => CustomFieldObj, Value => $DefaultValue );
> }
> return 1;
> Custom action cleanup code: return 1;
> 
> It seems correct but I don't now why It isn't working, AddCustomFieldValue seems to be the correct method because API says:
> 
> "AddCustomFieldValue { Field => FIELD, Value => VALUE }
> 
> VALUE should be a string. FIELD can be a CustomField object OR a CustomField ID.
> 
> Adds VALUE as a value of CustomField FIELD. If this is a single-value custom field, deletes the old value. If VALUE isn't a valid value for the custom field, returns (0, 'Error message' ) otherwise, returns (1, 'Success Message')"
> 
> "If VALUE isn't a valid value for the custom field" makes me think that VALUE must be valid because this method sets the custom field value to VALUE.

Oh wait, you're going global, so there's no QueueObj in the
$self->TicketObj->QueueObj->CustomFields() piece.  Hrm...  I actually
have never fiddled with global custom fields.  I don't know quite what
to use there.  I just took a look at the CustomFields_Overlay.pm
perldoc.  It looks like this may work:

my $CustomFieldsObj = RT::CustomFields->new( $session{ 'CurrentUser' } );
$CustomFieldsObj->LimitToGlobal;

while ( my $CustomFieldObj = $CustomFieldsObj->Next() ) {
   next unless $CustomFieldObj->Name = "Provider";
   ....  your SetContent code...
}


And AddCustomFieldValue isn't right.  What it does is not add a value
to the custom field for your ticket.  It adds a new choice.  So right
now, one of your custom fields is called "Provider" and one it's
possible values (presumably) is "BT" (depending on what type of custom
field Provider is... single, multiple, etc).  So what you're trying to
do is add another choice to the list of possibilities.  So if Provider
had the possible choices of BT, Foo, Bar, or Baz, the user could pick
any of those as a choice for the Provider custom field.  What the
AddCustomFieldValue does is to add another choice to the list of
possibilities.  It does not add a value to the Provider custom field
of the current ticket.

-- 
Andy Harrison


More information about the Rt-devel mailing list