Problem with DefaultCustomFieldValue

I tried to create this global and queue specific script without success, I have a Global Ticket Custom Field “Provider” It’s a select one value field the default value I want to use is “BT” instead of “(no value)”

Condition: On Transaction
Custom Condition:
Action: User defined
Custom action preparation code: return 1;
Custom action cleanup code:
my $CFName = ‘Tipo’;
my $DefaultValue = ‘Generica’;
my $RecTransaction = 1;

my $QueueObj = $self->TicketObj->QueueObj;
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->warning( “$CFName doesn’t exist, Queue -”. $QueueObj->Name ."-" );
return undef;
}
}

unless( $self->TicketObj->FirstCustomFieldValue( $CFObj->id ) ) {
my( $st, $msg ) = $self->TicketObj->AddCustomFieldValue(
Field => $CFObj->id,
Value => $DefaultValue,
RecordTransaction => $RecTransaction );
unless( $st ) {
$RT::Logger->warning( “Couldn’t set $DefaultValue as value for CF $CFName:”. $msg );
return undef;
}
}
return 1;
Template: Global template: Blank

Any suggestions?

Thanks.

RT 3.4.1
RTIR 1.1.5

my( $st, $msg ) = $self->TicketObj->AddCustomFieldValue(

I believe this is your problem. IIRC, the AddCustomFieldValue method
attempts to add to the available choices for this custom field. I
think you want the SetContent method. See the perldoc in
TicketCustomFieldValue_Overlay.pm and TicketCustomFieldValue.pm.

Andy Harrison

Sorry I can’t find TicketCustomFieldValue.pm or TicketCustomFieldValue_Overlay.pm in RT 3.4.1.

Sorry I can’t find TicketCustomFieldValue.pm or TicketCustomFieldValue_Overlay.pm in RT 3.4.1.

my( $st, $msg ) = $self->TicketObj->AddCustomFieldValue(

I believe this is your problem. IIRC, the AddCustomFieldValue method
attempts to add to the available choices for this custom field. I
think you want the SetContent method. See the perldoc in
TicketCustomFieldValue_Overlay.pm and TicketCustomFieldValue.pm.

Looks like it’s ObjectCustomFieldValue now.

Andy Harrison

Yes it seems correct, but in this case the complete script must be rewritten I think the structure changed completely then old methods probably aren’t going to work now, It’s that possible?

Thanks :slight_smile:

Juan Ramón Alfageme Mata
+34 91 787 23 00 alhambra-eidos.comDe: Andy Harrison [mailto:aharrison@gmail.com]
Enviado el: martes, 22 de febrero de 2005 16:35
Para: Juan Ramón Alfageme Mata
CC: rt-devel@lists.bestpractical.com
Asunto: Re: [Rt-devel] Problem with DefaultCustomFieldValue

Sorry I can’t find TicketCustomFieldValue.pm or TicketCustomFieldValue_Overlay.pm in RT 3.4.1.

my( $st, $msg ) = $self->TicketObj->AddCustomFieldValue(

I believe this is your problem. IIRC, the AddCustomFieldValue method
attempts to add to the available choices for this custom field. I
think you want the SetContent method. See the perldoc in
TicketCustomFieldValue_Overlay.pm and TicketCustomFieldValue.pm.

Looks like it’s ObjectCustomFieldValue now.

Andy Harrison

Yes it seems correct, but in this case the complete script must be rewritten I think the structure changed completely then old methods probably aren’t going to work now, It’s that possible?

It doesn’t look like a rewrite is needed. I even notice in the
CustomField_Overlay.pm, there’s a reference to the new method name for
backward compatibility.

| # Change after 3.4 beta.
| *LoadByNameAndQueue = &LoadByName;

Andy Harrison

Now I have the following global and queue specific scripts, but still nothing happens.

Condition: On Transaction
Custom Condition:
Action: User defined
Custom action preparation code: return 1;
Custom action cleanup code:
my $CFName = ‘Provider’;
my $DefaultValue = ‘BT’;
my $RecTransaction = 1;

my $QueueObj = $self->TicketObj->QueueObj;
my $CFObj = RT::CustomField->new( $QueueObj->CurrentUser );
$CFObj->LoadByName( Name => $CFName, Queue => $QueueObj->id );
unless( $CFObj->id ) {
$CFObj->LoadByName( Name => $CFName, Queue => 0 );
unless( $CFObj->id ) {
$RT::Logger->warning( “$CFName doesn’t exist, Queue -”. $QueueObj->Name ."-" );
return undef;
}
}

unless( $self->TicketObj->FirstCustomFieldValue( $CFObj->id ) ) {
my( $st, $msg ) = $self->TicketObj->SetContent(
Field => $CFObj->id,
Value => $DefaultValue,
RecordTransaction => $RecTransaction );
unless( $st ) {
$RT::Logger->warning( “Couldn’t set $DefaultValue as value for CF $CFName:”. $msg );
return undef;
}
}
return 1;
Template: Global template: Blank

Any new idea about how to fix the script?.

Now I have the following global and queue specific scripts, but still nothing happens.

Condition: On Transaction
Custom Condition:
Action: User defined
Custom action preparation code: return 1;
Custom action cleanup code:
my $CFName = ‘Provider’;
my $DefaultValue = ‘BT’;
my $RecTransaction = 1;

my $QueueObj = $self->TicketObj->QueueObj;
my $CFObj = RT::CustomField->new( $QueueObj->CurrentUser );
$CFObj->LoadByName( Name => $CFName, Queue => $QueueObj->id );
unless( $CFObj->id ) {
$CFObj->LoadByName( Name => $CFName, Queue => 0 );
unless( $CFObj->id ) {
$RT::Logger->warning( “$CFName doesn’t exist, Queue -”. $QueueObj->Name ."-" );
return undef;
}
}

unless( $self->TicketObj->FirstCustomFieldValue( $CFObj->id ) ) {
my( $st, $msg ) = $self->TicketObj->SetContent(
Field => $CFObj->id,
Value => $DefaultValue,
RecordTransaction => $RecTransaction );
unless( $st ) {
$RT::Logger->warning( “Couldn’t set $DefaultValue as value for CF $CFName:”. $msg );
return undef;
}
}
return 1;
Template: Global template: Blank

I think you have your prep and cleanup blocks backwards. Try
switching that. You should probably wipe out either the global or
queue specific scrip while you’re testing. Unless that’s a global
custom field, you should probably wipe out the global scrip.

Andy Harrison

Hi list,
could someone explain what’s special with the
RT::Interface::Web that causes some code like the
folowwing one to end up with:

Undefined subroutine &RT::Interface::Web::MakeMIMEEntity called at
  /usr/local/share/request-tracker3/lib/RT/Foo/Bar.pm

package RT::Foo::Bar;
use strict;

sub Baz {
my $self = shift;

use RT::Interface::Web;

my $MIMEObj = &RT::Interface::Web::MakeMIMEEntity(
    Subject             => 'value',
    From                => 'value',
    Cc                  => 'value',
    Body                => 'value',
);

}

1;

best regards

levon ghazaryan
levon@mail.desy.de

Hi Levon,
I’m not sure if it’s the preferred method or not, but I was able to just use
the MIME::Tools module to create my MIME entity in a scrip:

use MIME::Entity;

my $entity = MIME::Entity->build(
	Subject => "subject"
	From => 'value',
    	Cc => 'value',
    	Data => 'value',
);

Is this sufficient for what you want to do? If not, sorry for muddying the
waters.

Cheers,
Jeff Albert
Departmental Computing Support Team
University of Victoria
jralbert@uvic.ca-----Original Message-----
From: rt-devel-bounces@lists.bestpractical.com
[mailto:rt-devel-bounces@lists.bestpractical.com] On Behalf Of Levon
Ghazaryan
Sent: Friday, February 25, 2005 8:35 AM
To: rt-devel@lists.bestpractical.com
Subject: [Rt-devel] &RT::Interface::Web::MakeMIMEEntity()

Hi list,
could someone explain what’s special with the
RT::Interface::Web that causes some code like the
folowwing one to end up with:

Undefined subroutine &RT::Interface::Web::MakeMIMEEntity called at
  /usr/local/share/request-tracker3/lib/RT/Foo/Bar.pm

package RT::Foo::Bar;
use strict;

sub Baz {
my $self = shift;

use RT::Interface::Web;

my $MIMEObj = &RT::Interface::Web::MakeMIMEEntity(
    Subject             => 'value',
    From                => 'value',
    Cc                  => 'value',
    Body                => 'value',
);

}

1;

best regards

levon ghazaryan
levon@mail.desy.de
Rt-devel mailing list
Rt-devel@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel

Hi Jeff,

I’m not sure if it’s the preferred method or not, but I was able to just use
the MIME::Tools module to create my MIME entity in a scrip:

exactly what I’ve swetched to now:)

off course it’s not as importand to use the
RT::Interface::Web::MakeMIMEEntity instead but i was just
wondering why this shouldn’t work. i’ve to admit that perl & mod_perl is
not the programing environment of my daily use, so maybe i’m
just missing something very importand with Web.pm :smiley:

thax a lot for the response!

Cheers,
~levonOn Fri, 25 Feb 2005, Jeff Albert wrote:

Hi Levon,
I’m not sure if it’s the preferred method or not, but I was able to just use
the MIME::Tools module to create my MIME entity in a scrip:

use MIME::Entity;

my $entity = MIME::Entity->build(
Subject => "subject"
From => ‘value’,
Cc => ‘value’,
Data => ‘value’,
);

Is this sufficient for what you want to do? If not, sorry for muddying the
waters.

Cheers,
Jeff Albert
Departmental Computing Support Team
University of Victoria
jralbert@uvic.ca

-----Original Message-----
From: rt-devel-bounces@lists.bestpractical.com
[mailto:rt-devel-bounces@lists.bestpractical.com] On Behalf Of Levon
Ghazaryan
Sent: Friday, February 25, 2005 8:35 AM
To: rt-devel@lists.bestpractical.com
Subject: [Rt-devel] &RT::Interface::Web::MakeMIMEEntity()

Hi list,
could someone explain what’s special with the
RT::Interface::Web that causes some code like the
folowwing one to end up with:

Undefined subroutine &RT::Interface::Web::MakeMIMEEntity called at
  /usr/local/share/request-tracker3/lib/RT/Foo/Bar.pm

package RT::Foo::Bar;
use strict;

sub Baz {
my $self = shift;

use RT::Interface::Web;

my $MIMEObj = &RT::Interface::Web::MakeMIMEEntity(
    Subject             => 'value',
    From                => 'value',
    Cc                  => 'value',
    Body                => 'value',
);

}

1;

best regards

levon ghazaryan

levon@mail.desy.de


Rt-devel mailing list
Rt-devel@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel

Hi,

You used:

&RT::Interface::Web::MakeMIMEEntity(

actualy I’ve tried both, should there be any diference?

Perhaps you needed to try:

RT::Interface::Web::MakeMIMEEntity(

Levon Ghazaryan wrote:

Hi Jeff,

I’m not sure if it’s the preferred method or not, but I was able to just use
the MIME::Tools module to create my MIME entity in a scrip:

exactly what I’ve swetched to now:)

off course it’s not as importand to use the
RT::Interface::Web::MakeMIMEEntity instead but i was just
wondering why this shouldn’t work. i’ve to admit that perl & mod_perl is
not the programing environment of my daily use, so maybe i’m
just missing something very importand with Web.pm :smiley:

thax a lot for the response!

Cheers,
~levon

Hi Levon,
I’m not sure if it’s the preferred method or not, but I was able to just use
the MIME::Tools module to create my MIME entity in a scrip:

use MIME::Entity;

my $entity = MIME::Entity->build(
Subject => "subject"
From => ‘value’,
Cc => ‘value’,
Data => ‘value’,
);

Is this sufficient for what you want to do? If not, sorry for muddying the
waters.

Cheers,
Jeff Albert
Departmental Computing Support Team
University of Victoria
jralbert@uvic.ca

-----Original Message-----
From: rt-devel-bounces@lists.bestpractical.com
[mailto:rt-devel-bounces@lists.bestpractical.com] On Behalf Of Levon
Ghazaryan
Sent: Friday, February 25, 2005 8:35 AM
To: rt-devel@lists.bestpractical.com
Subject: [Rt-devel] &RT::Interface::Web::MakeMIMEEntity()

Hi list,
could someone explain what’s special with the
RT::Interface::Web that causes some code like the
folowwing one to end up with:

Undefined subroutine &RT::Interface::Web::MakeMIMEEntity called at
/usr/local/share/request-tracker3/lib/RT/Foo/Bar.pm

package RT::Foo::Bar;
use strict;

sub Baz {
my $self = shift;

use RT::Interface::Web;

my $MIMEObj = &RT::Interface::Web::MakeMIMEEntity(
Subject => ‘value’,
From => ‘value’,
Cc => ‘value’,
Body => ‘value’,
);
}

1;

best regards

levon ghazaryan

levon@mail.desy.de


Rt-devel mailing list
Rt-devel@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel


Rt-devel mailing list
Rt-devel@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel

best regards

levon ghazaryan
UCO Student
levon@mail.desy.de

You used:

&RT::Interface::Web::MakeMIMEEntity(

Perhaps you needed to try:

RT::Interface::Web::MakeMIMEEntity(

Levon Ghazaryan wrote:

I tried swapping both (cleanup and preparation code) I tried too using global and queue scripts alone and together.

Custom field is global.

Juan Ramón Alfageme Mata
+34 91 787 23 00 alhambra-eidos.comDe: Andy Harrison [mailto:aharrison@gmail.com]
Enviado el: viernes, 25 de febrero de 2005 15:19
Para: Juan Ramón Alfageme Mata
CC: rt-devel@lists.bestpractical.com
Asunto: Re: [Rt-devel] Problem with DefaultCustomFieldValue

Now I have the following global and queue specific scripts, but still nothing happens.

Condition: On Transaction
Custom Condition:
Action: User defined
Custom action preparation code: return 1;
Custom action cleanup code:
my $CFName = ‘Provider’;
my $DefaultValue = ‘BT’;
my $RecTransaction = 1;

my $QueueObj = $self->TicketObj->QueueObj;
my $CFObj = RT::CustomField->new( $QueueObj->CurrentUser );
$CFObj->LoadByName( Name => $CFName, Queue => $QueueObj->id );
unless( $CFObj->id ) {
$CFObj->LoadByName( Name => $CFName, Queue => 0 );
unless( $CFObj->id ) {
$RT::Logger->warning( “$CFName doesn’t exist, Queue -”. $QueueObj->Name ."-" );
return undef;
}
}

unless( $self->TicketObj->FirstCustomFieldValue( $CFObj->id ) ) {
my( $st, $msg ) = $self->TicketObj->SetContent(
Field => $CFObj->id,
Value => $DefaultValue,
RecordTransaction => $RecTransaction );
unless( $st ) {
$RT::Logger->warning( “Couldn’t set $DefaultValue as value for CF $CFName:”. $msg );
return undef;
}
}
return 1;
Template: Global template: Blank

I think you have your prep and cleanup blocks backwards. Try
switching that. You should probably wipe out either the global or
queue specific scrip while you’re testing. Unless that’s a global
custom field, you should probably wipe out the global scrip.

Andy Harrison

I tried swapping both (cleanup and preparation code) I tried too using global and queue scripts alone and together.

Custom field is global.

Juan Ramón Alfageme Mata
+34 91 787 23 00 alhambra-eidos.com

Instead of LoadByNameAndQueue, why not try it this way:

my $CustomFieldsObj = $self->TicketObj->QueueObj->CustomFields();

while ( my $CustomFieldObj = $CustomFieldsObj->Next() ) {
next unless $CustomFieldObj->Name = “Tipo”;
… your SetContent code…
}

Andy Harrison

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.

Thanks for your patience and help.

Juan Ramón Alfageme Mata
+34 91 787 23 00 alhambra-eidos.com

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

Now I modified code as follows, I tried using AddCustomFieldValue, global and queue specific script, and including it as cleanup and preparation, in every possible combination, but still no way.

SetContent is a method from CustomFieldValue It isn’t a Ticket method maybe that’s the problem.

my $CFName = ‘Provider’;
my $DefaultValue = ‘BT’;

my $CustomFieldsObj = RT::CustomFields->new( $session{ ‘CurrentUser’ } ); $CustomFieldsObj->LimitToGlobal;
while ( my $CustomFieldObj = $CustomFieldsObj->Next() ) {
next unless ( $CustomFieldObj->Name = $CFName ) {
my( $st, $msg ) = $self->TicketObj->SetContent( Field => CustomFieldObj->id , Value => $DefaultValue );
}
return 1;

Juan Ramón Alfageme Mata
+34 91 787 23 00 alhambra-eidos.com

my( $st, $msg ) = $self->TicketObj->SetContent( Field => CustomFieldObj->id , Value => $DefaultValue );

You’re missing a ‘$’ on CustomFieldObj->id
Andy Harrison