Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Request Tracker: Users

Fetching custom field id by a non-unique name

 

 

Request Tracker users RSS feed   Index | Next | Previous | View Threaded


reg.bestpractical at posterus

Mar 22, 2012, 5:27 PM

Post #1 of 3 (460 views)
Permalink
Fetching custom field id by a non-unique name

Hello,

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.


Maciek


falcone at bestpractical

Mar 22, 2012, 7:47 PM

Post #2 of 3 (462 views)
Permalink
Re: Fetching custom field id by a non-unique name [In reply to]

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


reg.bestpractical at posterus

Mar 23, 2012, 2:00 PM

Post #3 of 3 (437 views)
Permalink
Re: Fetching custom field id by a non-unique name [In reply to]

Kevin,

> 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.

Somehow I was perceiving using RT::CustomFields as not very efficient way to
do it. I was afraid it would be scanning all fields, but I can now see that
the filters there can work pretty well even on the SQL layer. Thanks.

Maciek

Request Tracker users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.