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

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

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