Custom Field values are being deleted on ticket modification

Hi there,

I am working on a customization script that should issue a number of
configuration changes in a vainilla RT 3.6.7 as shipped with Debian
Lenny.

The snippet below should create 4 custom fields that would apply to the
General queue, and add a couple of test values to them:

#!/usr/bin/perl
use lib ‘/usr/share/request-tracker3.6/lib’;
use strict; use warnings; use RT; use RT::User; use RT::Queue;
use RT::Template;
RT::LoadConfig;
RT::Init;

for my $d ( [ Field1 => ‘My Field 1’, { One => ‘Value One’,
Two => ‘Value Two’, }],
[ Field2 => ‘My Field 2’, { One => ‘Value One’,
Two => ‘Value Two’, }],
[ Field3 => ‘My Field 3’, { One => ‘Value One’,
Two => ‘Value Two’, }],
[ Field4 => ‘My Field 4’, { One => ‘Value One’,
Two => ‘Value Two’, }],)
{
my $cf = new RT::CustomField ( $RT::SystemUser );
my ($id, $msg) = $cf->Create(
Name => $d->[0],
Description => $d->[1],
Type => ‘Combobox’,
LookupType => ‘RT::Queue-RT::Ticket’,
Pattern => ‘(?#Mandatory).’,
);
print 'Cannot create CF ’ . $d->[0] . “: $msg\n” unless $id;
my $order = 0;
for my $val (sort keys %{$d->[2]})
{
my ($d, $msg) = $cf->AddValue(Name => $d->[2]->{$val},
Description => $d->[2]->{$val},
SortOrder => $order);
print “Value $val: $msg \n”;
$order += 5;
}

for my $queue (qw/General/)
{

my $q = RT::Queue->new($RT::SystemUser);
$q->Load($queue);
my ($id, $msg) = $cf->AddToObject($q);
print “Can’t link CF to queue $queue: $msg\n” unless $id;
}
}

After the script is run, I can see the fields through Configuration >
Custom Fields, with the intended values. When I try to create a ticket
in the General queue, the corresponding combo boxes are populated with
the expected values. So far so good.

When the ticket is created, the CF values are stored along with the
ticket and I can see them in the display.

Whenever I try to change the ticket (say, modify the value of a CF), the
following messages are displayed in my browser before the Basic form:

  • Value Two added as a value for Field1
    • Value Two is no longer a value for custom field Field2
    • Value Two is no longer a value for custom field Field3
    • Value One is no longer a value for custom field Field4

The ticket losses the CF values… This is what the logs say.

Dec 16 05:06:33 rt RT: Ticket 1 created in queue ‘General’ by root
(/usr/share/request-tracker3.6/lib/RT/Ticket_Overlay.pm:756)#012
Dec 16 05:06:42 rt RT: About to think about scrips for transaction
#27#012
Dec 16 05:06:42 rt RT: About to prepare scrips for transaction #27#012
Dec 16 05:06:42 rt RT: Found 1 scrips#012
Dec 16 05:06:42 rt RT: About to commit scrips for transaction #27#012
Dec 16 05:06:42 rt RT: About to think about scrips for transaction
#28#012
Dec 16 05:06:42 rt RT: About to prepare scrips for transaction #28#012
Dec 16 05:06:42 rt RT: Found 1 scrips#012
Dec 16 05:06:42 rt RT: About to commit scrips for transaction #28#012
Dec 16 05:06:42 rt RT: About to think about scrips for transaction
#29#012
Dec 16 05:06:42 rt RT: About to prepare scrips for transaction #29#012
Dec 16 05:06:42 rt RT: Found 1 scrips#012
Dec 16 05:06:42 rt RT: About to commit scrips for transaction #29#012
Dec 16 05:06:42 rt RT: About to think about scrips for transaction
#30#012
Dec 16 05:06:42 rt RT: About to prepare scrips for transaction #30#012
Dec 16 05:06:42 rt RT: Found 1 scrips#012
Dec 16 05:06:42 rt RT: About to commit scrips for transaction #30#012

After reading through the source, I have been unable to find what am I
missing in my code. Can someone point me in the right direction?

Thanks and best regards.

-lem

Luis,

I had trouble awhile back with Custom Field values not being set at all
during the execution of a scrip, while all other changes took place
correctly. The cause turned out to be that I had set the stage in the
scrips to “TransactionCreate” instead of “TransactionBatch”. Try that.
Remember, you have to turn on “TransactionBatch” in your
RT_SiteConfiguration.pm file and bounce your session.

Kenn
LBNLOn 12/16/2009 6:38 AM, Luis E. Mu�oz wrote:

Hi there,

I am working on a customization script that should issue a number of
configuration changes in a vainilla RT 3.6.7 as shipped with Debian
Lenny.

The snippet below should create 4 custom fields that would apply to the
General queue, and add a couple of test values to them:

#!/usr/bin/perl
use lib ‘/usr/share/request-tracker3.6/lib’;
use strict; use warnings; use RT; use RT::User; use RT::Queue;
use RT::Template;
RT::LoadConfig;
RT::Init;

for my $d ( [ Field1 => ‘My Field 1’, { One => ‘Value One’,
Two => ‘Value Two’, }],
[ Field2 => ‘My Field 2’, { One => ‘Value One’,
Two => ‘Value Two’, }],
[ Field3 => ‘My Field 3’, { One => ‘Value One’,
Two => ‘Value Two’, }],
[ Field4 => ‘My Field 4’, { One => ‘Value One’,
Two => ‘Value Two’, }],)
{
my $cf = new RT::CustomField ( $RT::SystemUser );
my ($id, $msg) = $cf->Create(
Name => $d->[0],
Description => $d->[1],
Type => ‘Combobox’,
LookupType => ‘RT::Queue-RT::Ticket’,
Pattern => ‘(?#Mandatory).’,
);
print 'Cannot create CF ’ . $d->[0] . “: $msg\n” unless $id;
my $order = 0;
for my $val (sort keys %{$d->[2]})
{
my ($d, $msg) = $cf->AddValue(Name => $d->[2]->{$val},
Description => $d->[2]->{$val},
SortOrder => $order);
print “Value $val: $msg \n”;
$order += 5;
}

for my $queue (qw/General/)
{

my $q = RT::Queue->new($RT::SystemUser);
$q->Load($queue);
my ($id, $msg) = $cf->AddToObject($q);
print “Can’t link CF to queue $queue: $msg\n” unless $id;
}
}

After the script is run, I can see the fields through Configuration >
Custom Fields, with the intended values. When I try to create a ticket
in the General queue, the corresponding combo boxes are populated with
the expected values. So far so good.

When the ticket is created, the CF values are stored along with the
ticket and I can see them in the display.

Whenever I try to change the ticket (say, modify the value of a CF), the
following messages are displayed in my browser before the Basic form:

  • Value Two added as a value for Field1
    • Value Two is no longer a value for custom field Field2
    • Value Two is no longer a value for custom field Field3
    • Value One is no longer a value for custom field Field4

The ticket losses the CF values… This is what the logs say.

Dec 16 05:06:33 rt RT: Ticket 1 created in queue ‘General’ by root
(/usr/share/request-tracker3.6/lib/RT/Ticket_Overlay.pm:756)#012
Dec 16 05:06:42 rt RT: About to think about scrips for transaction
#27#012
Dec 16 05:06:42 rt RT: About to prepare scrips for transaction #27#012
Dec 16 05:06:42 rt RT: Found 1 scrips#012
Dec 16 05:06:42 rt RT: About to commit scrips for transaction #27#012
Dec 16 05:06:42 rt RT: About to think about scrips for transaction
#28#012
Dec 16 05:06:42 rt RT: About to prepare scrips for transaction #28#012
Dec 16 05:06:42 rt RT: Found 1 scrips#012
Dec 16 05:06:42 rt RT: About to commit scrips for transaction #28#012
Dec 16 05:06:42 rt RT: About to think about scrips for transaction
#29#012
Dec 16 05:06:42 rt RT: About to prepare scrips for transaction #29#012
Dec 16 05:06:42 rt RT: Found 1 scrips#012
Dec 16 05:06:42 rt RT: About to commit scrips for transaction #29#012
Dec 16 05:06:42 rt RT: About to think about scrips for transaction
#30#012
Dec 16 05:06:42 rt RT: About to prepare scrips for transaction #30#012
Dec 16 05:06:42 rt RT: Found 1 scrips#012
Dec 16 05:06:42 rt RT: About to commit scrips for transaction #30#012

After reading through the source, I have been unable to find what am I
missing in my code. Can someone point me in the right direction?

Thanks and best regards.

-lem


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 had trouble awhile back with Custom Field values not being set at
all
during the execution of a scrip, while all other changes took place
correctly. The cause turned out to be that I had set the stage in the
scrips to “TransactionCreate” instead of “TransactionBatch”. Try
that.
Remember, you have to turn on “TransactionBatch” in your
RT_SiteConfiguration.pm file and bounce your session.

Hi Ken, thanks for your suggestion.

I did see your messages when researching the archives before submitting
my question. However, I’m not sure how to apply this to my scenario. The
snippet I posted is not running as part of a scrip; This is a stand
alone script to be run right after a fresh install of RT, to bring it to
the desired configuration for the customer.

As such, I don’t see where a transaction might come in… Any
enlightenment is appreciated :slight_smile:

Best regards.

-lem

Luis,

Then I am confused. If you have installed RT and are simply trying to
set values for some Custom Fields before the customer uses RT, then why
not simply use the “Bulk Update” feature? If you can identify the
tickets in any way, that would be the way I would do it. I had a
customer that added 1700 tickets 'en masse. What he did was put
"bulk-specific" info in the “Subject” field that allowed us to identify
the records we wanted to “bulk update” with certain CF values. It took a
little time, but worked like a charm. Sorry that’s all the help I can
provide.

Kenn
LBNLOn 12/17/2009 5:50 AM, Luis E. Mu�oz wrote:

On Wed, 2009-12-16 at 09:12 -0800, Ken Crocker wrote:

I had trouble awhile back with Custom Field values not being set at
all
during the execution of a scrip, while all other changes took place
correctly. The cause turned out to be that I had set the stage in the
scrips to “TransactionCreate” instead of “TransactionBatch”. Try
that.
Remember, you have to turn on “TransactionBatch” in your
RT_SiteConfiguration.pm file and bounce your session.

Hi Ken, thanks for your suggestion.

I did see your messages when researching the archives before submitting
my question. However, I’m not sure how to apply this to my scenario. The
snippet I posted is not running as part of a scrip; This is a stand
alone script to be run right after a fresh install of RT, to bring it to
the desired configuration for the customer.

As such, I don’t see where a transaction might come in… Any
enlightenment is appreciated :slight_smile:

Best regards.

-lem

If you have installed RT and are simply trying to set values for some
Custom Fields before the customer uses RT, then why not simply use the
"Bulk Update" feature? If you can identify the tickets in any way,
that would be the way I would do it. I had a customer that added 1700
tickets 'en masse. What he did was put “bulk-specific” info in the
"Subject" field that allowed us to identify the records we wanted to
"bulk update" with certain CF values. It took a little time, but
worked like a charm. Sorry that’s all the help I can provide.

The script is responsible for doing the configuration before shipping to
the customer. (ie, the system contains no tickets / users at that time).
The script is run so that queues, groups, permissions, etc. are set up
automatically and consistently.

I am now trying to add the CF definitions and allowed values for the
comboboxes, so the setup is complete out of the box.

Thanks for your help.

Regards.

-lem