[rt-devel] Getting Custom Fields for a User

Ruslan Zakirov ruslan.zakirov at gmail.com
Sat Apr 21 23:53:23 EDT 2012

Ruslan from phone.
22.04.2012 1:30 пользователь "Lee Wilson" <leefm40 at yahoo.co.uk> написал:
> On 16/04/2012 22:15, Ruslan Zakirov wrote:
>> On Mon, Apr 16, 2012 at 23:29, Lee Wilson<leefm40 at yahoo.co.uk>  wrote:
>>> Hi Ruslan,
>>> Thanks for that. Looking at the perldoc for User.pm doesn't give any
>>> of that but I guess it's inherited from Record.pm
>> Right. In theory CFs can be on any object in the system, so methods
>> are in Record.pm.
> <snip>
> Thanks for the detailed reply Ruslan it's really helped me understand
things.  In the meantime I've read about the RT:SystemUSer which may do
things more like I want to as all I need to be able to do is get the values
for the users custom fields when creating/editing a ticket.
> I'm now a bit stuck on how to retrieve the values for the custom fields.
Perhaps if I explain more what I'm trying to do someone be so kind as to
explain the bit i've missed/got wrong:
> 1) Requestor creates a ticket
> 2) Upon the new ticket window loading, lookup the Account ID stored in
the users custom field
> 3) Based on the Account ID display a list of services (stored in a
seperate database/CRM) in a dropdown <-- got this bit working independently
just not with RT.
> 4) Store the id of the selected service into a hidden ticket custom field.
> I've got a few more processes that I wish to get working but the basic
process is the same.
> So far I've got as far as coding the following test routine is
MassageCustomFields but can't get it to show the values of the associated
current user:
> % if ($CustomFields->First) {
> Ok we've found some custom fields:<br />
> % $CustomFields->GotoFirstItem;
> <% $session{'CurrentUser'}->id %><br /> <-------- This Id displays fine
> % while ( my $CustomField = $CustomFields->Next) {
> <% loc($CustomField->Name) %> <------ Name of the custom field shows up
> % $CustomField->Load($CustomField->Name);
> <% $CustomField->ValuesForObject($session{'CurrentUser'}) %>
> <br />
> % }
> % }
> On the last line it returns a reference to 'RT::ObjectCustomFieldValues'
but I can't figure out how to get the currently selected/filled in value.

First of all every object has CustomFieldValues method that return the same
thing. So after getting name of a CF you can call it on

ObjectCustomFieldValues is just another collection you walk with Next and
while loop. If you know for sure that all fields are single value then you
can use FirstCustomFieldValue.

> Once again, thanks for all your help so far.
> Lee
> --------
> List info:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-devel/attachments/20120422/91076f70/attachment.html>

More information about the rt-devel mailing list