[rt-users] Fetching custom field id by a non-unique name

Kevin Falcone falcone at bestpractical.com
Thu Mar 22 22:47:04 EDT 2012


On Fri, Mar 23, 2012 at 01:27:48AM +0100, Maciej Dobrzanski wrote:
> I created two custom fields called "Customer ID" - one is for Ticket object,
> while the other is for User. The name is not unique, but these are two
> different CFs with different identifiers. In a callback I need to figure out
> the appropriate field id depending on the context - whether a ticket or a
> user details are being displayed. However the normal interface does not
> really seem to allow that. In RT::CustomField, LoadByName() only takes field
> name and optionally also queue name/id(?). The effect is that
> LoadByName(Name => 'Customer ID') always loads the "first" CF it finds by
> the name 'Customer ID', which does not necessarily mean the right one. Is
> there any other way around it or do I really need to loop through all the
> CFs as RT::CustomFields comes with LimitToLookupType(), which might allow
> looping through RT::Queue-RT::Ticket or RT::User fields as needed.

There are a number of ways to do it.
Make a custom fields collection, LimitToLookupType and also use Limit
to limit on the Name.  Call CustomFields on a Ticket or User object
and then Limit that collection to a particular name.

You can string multiple Limit calls together to build more complex
queries.  You can read more about the syntax in DBIx::SearchBuilder.

-kevin
-------------- 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/20120322/5d788700/attachment.sig>


More information about the rt-users mailing list