[rt-users] My problem with the user custom fields

Kevin Falcone falcone at bestpractical.com
Fri Dec 10 12:04:54 EST 2010


On Fri, Dec 10, 2010 at 01:24:05PM +0100, Wolfram Huettermann wrote:
> Hi again,
> 
> I wrote two scripts in order to describe my problem concerning user
> custom fields. I can say that everything works with ticket custom
> fields.

Hi Wolfram

If this came as an RT test file that failed, it'd be a lot easier for
me to sort out what you want it to be doing.  As is, I need to set up
an RT and tweak custom field ids in order to see the behavior.

There should be a t/api/cf.t that has some skeleton code for you
to steal.

Thanks

-kevin

> 
> 
> #!/usr/bin/perl -w
> use strict;
> 
> use lib "/opt/rt3/local/lib",  "/opt/rt3/lib";
> 
> use RT;
> use Getopt::Long;   # Load the config file
> RT::LoadConfig();
> 
> # Connect to the database and get RT::SystemUser
> #  loaded
> RT::Init();
> use RT::Interface::CLI "GetCurrentUser", "loc";
> my $CurrentUser = GetCurrentUser();
> use RT::Tickets;
> use RT::Template;
> 
> 
> my $TId;
> # The costumfield #96 is a ticket customfield whose name is
> # 'RTIM_App_Name'
> my ($RTIMAppId, $RTIMAppName) = (96, "RTIM_App_Name");
> # The strings are the values that custom field will contain
> my ($String1, $String2) = ("UNIX 2010", "UNIX 2015");
> my $Ticket = RT::Ticket->new($CurrentUser);
> # The number has to be an id of an existing ticket!
> $Ticket->Load(318616);
> # Let us define two Ticket collections
> my $Tickets1 = new RT::Tickets($CurrentUser);
> my $Tickets2 = new RT::Tickets($CurrentUser);
> # The customfield #96 of the tickent #318616 is being changed to
> 'UNIX 2010'.
> $Ticket->AddCustomFieldValue("Field" => $RTIMAppName, "Value" => $String1,
>                             "RecordTransaction" => 0);
> $Tickets1->LimitCustomField("CUSTOMFIELD" => $RTIMAppId,
>                            "OPERATOR" => "=",
>                            "VALUE" => $String1);
> #Ticket #318616 occurs
> print "Tickets with $RTIMAppName = \'$String1\'\n\n";
> while (my $Entry = $Tickets1->Next())
> {
>    print join("\t", ($Entry->Id, $Entry->Created, $Entry->Subject)),"\n";
> }
> # The customfield #96 of the tickent #318616 is being changed to
> 'UNIX 2015' .
> $Ticket->AddCustomFieldValue("Field" => $RTIMAppName, "Value" => $String2,
>                            "RecordTransaction" => 0);
> # $Ticket2 refers to the updated collection
> $Tickets2->LimitCustomField("CUSTOMFIELD" => $RTIMAppId,
>                            "OPERATOR" => "=",
>                            "VALUE" => $String1);
> # Ticket #318616 does not occur anymore.
> print "Tickets with $RTIMAppName = \'$String1\'\n\n";
> 
> while (my $Entry = $Tickets2->Next())
> {
>    print join("\t", ($Entry->Id, $Entry->Created, $Entry->Subject)),"\n";
> }
> 
> and here is script #2
> 
> #!/usr/bin/perl -w
> # notwendige Header Anfang
> use strict;
> 
> use lib "/opt/rt3/RTIM/lib",  "/opt/rt3/lib";
> 
> use RT;
> 
> # Load the config file
> RT::LoadConfig();
> 
> # Connect to the database and get RT::SystemUser
> #  loaded
> RT::Init();
> use RT::Interface::CLI "GetCurrentUser", "loc";
> # notwendige Header Ende
> use RT::Users;
> use UserCF;
> 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 costumfield #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(4380);
> # The customfield #126 of the user #4380 is being changed to 'ABCDEFGHI'.
> $UserObject->AddCustomFieldValue("Field" => $MStatusName, "Value" =>
> $String1,"RecordTransaction" => 0);
> $Users1->LimitCustomField("CUSTOMFIELD" => $MStatusId,
>                         "OPERATOR" => "=",
>                         "VALUE" => $String1 );
> #User #4380 occurs
> 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 #4380 is being changed to 'RSTUVWXYZ'.
> $UserObject->AddCustomFieldValue("Field" => $MStatusName, "Value" =>
> $String2,"RecordTransaction" => 0);
> # $User2 refers to the updated collection
> $Users2->LimitCustomField("CUSTOMFIELD" => $MStatusId,
>                         "OPERATOR" => "=",
>                         "VALUE" => $String1 );
> #User #4380 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";
> }
> 
> I hope you eventually know what I meant. I apologise any misunderstandings.
> 
> Greetings,
> 
> Wolfram Huettermann
> 
> 
> 
> 
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20101210/bad66d7e/attachment.sig>


More information about the rt-users mailing list