[rt-users] Problem with CF for Users

Björn Schulz bjoern.schulz at desy.de
Fri Feb 4 08:11:46 EST 2011


Hi all,

we've a problem with custom fields for users on rt 3.8.8.

Here is my problem:

Step1
We add a value to a user cf, lets say 'String1 = ABCDEFGH'

$UserObject->AddCustomFieldValue("Field" => $MStatusName, "Value" =>
$String1,"RecordTransaction" => 0);

Step2
Then we limit a user object to this cf value to find all users with this
value in our user base.

$Users1->LimitCustomField("CUSTOMFIELD" => $MStatusId,
                         "OPERATOR" => "=",
                         "VALUE" => $String1 );

That works fine!

Step3 Error
We change the value from 'ABCDEFGH' to 'RSTUVWXYZ'
and limit the object to 'ABCDEFGH' the user with the new value is shown
in the result.

With Ticket objects this works fine.

Any comments?


Cheers,
 Björn


here is a little script that shows the problem:

#!/usr/bin/perl -w
use strict;
use lib "/opt/rt3/RTIM/lib",  "/opt/rt3/lib";
use RT;
RT::LoadConfig();
RT::Init();
use RT::Interface::CLI "GetCurrentUser", "loc";
use RT::Users;

my $CurrentUser = GetCurrentUser();
my $Users1 = new RT::Users($CurrentUser);
my $Users2 = new RT::Users($CurrentUser);
my $UserObject = RT::User->new($CurrentUser);
my ($String1, $String2) = ("ABCDEFGH", "RSTUVWXYZ");
# The customfield #126 is a user customfield whose name is
# 'MergeStatus'
my $MStatusId = 126;
my $MStatusName = "MergeStatus";
# The number has to be an id  of an existing user!
$UserObject->Load(14788);
# The customfield #126 of the user is being changed to 'ABCDEFGH'.
$UserObject->AddCustomFieldValue("Field" => $MStatusName, "Value" =>
$String1,"RecordTransaction" => 0);
$Users1->LimitCustomField("CUSTOMFIELD" => $MStatusId,
                         "OPERATOR" => "=",
                         "VALUE" => $String1 );

print "Users with the Status $String1\n";

while (my $UC = $Users1->Next())
{
    my $MStatusValue;
    my $CFValues = $UC->CustomFieldValues($MStatusId);
    while (my $CFValue = $CFValues->Next)
    {
        $MStatusValue = $CFValue->Content;
    }
    print join("\t", ($UC->Id, $UC->Name, $UC->RealName, $MStatusValue
)), "\n";
}
print "\n\n\n";

# The customfield #126 of the user is being changed to 'RSTUVWXYZ'.
$UserObject->DeleteCustomFieldValue("Field" => $MStatusName, "Value" =>
$String1,"RecordTransaction" => 0);
$UserObject->AddCustomFieldValue("Field" => $MStatusName, "Value" =>
$String2,"RecordTransaction" => 0);
# $User2 refers to the updated collection
$Users2->LimitCustomField("CUSTOMFIELD" => $MStatusId,
                         "OPERATOR" => "=",
                         "VALUE" => $String1 );
#User still occurs, although he should not occur anymore!
print "Users with the Status $String1\n";
while (my $UC = $Users1->Next())
{
    my $MStatusValue;
    my $CFValues = $UC->CustomFieldValues($MStatusId);
    while (my $CFValue = $CFValues->Next)
    {
        $MStatusValue = $CFValue->Content;
    }
    print join("\t", ($UC->Id, $UC->Name, $UC->RealName, $MStatusValue
)), "\n";
}



More information about the rt-users mailing list