[rt-users] Setting user CustomField through Perl Script

Jason Fenner jfenner at vitamix.com
Thu Mar 30 13:50:18 EST 2006


Ok, that makes sense.  I tried it now and it works good.  Two other 
things though...

1) How would you work in the reverse, meaning, how would you print what 
value(s) a certain CF has set? 
2) Where is the structure of the RT clases documented?  How does one 
find what class is related to which one?


Ruslan Zakirov wrote:

>On 3/30/06, Jason Fenner <jfenner at vitamix.com> wrote:
>  
>
>>I have tried your recommendation but I am getting this error message:
>>[Thu Mar 30 16:00:19 2006] [error]: Couldn't add CF value: Custom field
>>7 does not apply to this object (test2.pl:57)
>>    
>>
>look into Configuration->Custom FIelds->CF XXX->Applies to.
>
>
>  
>
>>I guess my question is regarding your example.  Is $user supposed to by
>>a RT::Record object or a RT::User object?
>>    
>>
>RT::User is a RT::Record, it's subclass of the RT::Record class.
>
>
>  
>
>>
>>The code I am trying is:
>>-------------------------------------------------------------------------------------------------------
>>my $CurrentUser = new RT::CurrentUser($RT::SystemUser);
>>
>>    # Try username first
>>#    $CurrentUser->LoadByName($name) if $name;
>>
>>#my $CustomFields = RT::CustomFields->new($CurrentUser);
>>my $record = new RT::Record($CurrentUser);
>>
>>
>>#my $user = new RT::User->Load("JDF");
>>my ($status, $msg) = $record->AddCustomFieldValue( Field =>'7', Value =>
>>'000 - Corporate');
>>$RT::Logger->error("Couldn't add CF value: $msg") unless $status;
>>    
>>
>your code is wrong, Load doesn't return object, but changes state of
>the object. Code should be:
>
>my $user = RT::User->new( $RT::SystemUser );
>$user->Load("JDF");
>die "Couldn't load user" unless $user->id;
>my ($status, $msg) = $user->AddCustomFieldValue( Field =>'7', Value =>
>'000 - Corporate');
>$RT::Logger->error("Couldn't add CF value: $msg") unless $status;
>
>  
>
>>print $CurrentUser->Id;
>>print $CurrentUser->Name;
>>
>>---------------------------------------------------------------------------------------------------------------------
>>
>>Ruslan Zakirov wrote:
>>
>>    
>>
>>>my ($status, $msg) = $user->AddCustomFieldValue( Field =>
>>>'Department', Value => 'XXX');
>>>$RT::Logger->error("Couldn't add CF value: $msg") unless $status;
>>>
>>>perldoc lib/RT/Record.pm
>>>perldoc lib/RT/User*.pm
>>>perldoc ...
>>>
>>>On 3/29/06, Jason Fenner <jfenner at vitamix.com> wrote:
>>>
>>>
>>>      
>>>
>>>>Hi:
>>>>
>>>>I have a global CustomField called "Department" defined as type User in
>>>>my RT 3.4
>>>>
>>>>Through an external Perl script I query my Active Directory server for a
>>>>particular username and find a key called: Department.  Once I find that
>>>>key, I want to set the above CustomField for that user in RT to that
>>>>same value.
>>>>
>>>>However, I am stumped as to what object method, etc you use with RT in
>>>>order to set a CustomField value for a user?
>>>>
>>>>Can anyone toss me any clues?
>>>>
>>>>Thanks in advance,
>>>>Jason Fenner
>>>>
>>>>_______________________________________________
>>>>http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>>>>
>>>>Community help: http://wiki.bestpractical.com
>>>>Commercial support: sales at bestpractical.com
>>>>
>>>>
>>>>Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
>>>>Buy a copy at http://rtbook.bestpractical.com
>>>>
>>>>
>>>>We're hiring! Come hack Perl for Best Practical: http://bestpractical.com/about/jobs.html
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>--
>>>Best regards, Ruslan.
>>>
>>>
>>>      
>>>
>>
>>    
>>
>
>
>--
>Best regards, Ruslan.
>  
>





More information about the rt-users mailing list