[rt-devel] External custom fields - use of description value
Emmanuel Lacour
elacour at easter-eggs.com
Tue Oct 28 04:55:52 EDT 2014
On Sun, Oct 26, 2014 at 09:08:28PM +0200, Ben Kelly wrote:
> Hello,
> We are using a custom field in our RT environment with an external source
> to obtain selectable values. Our code is based on the documentation
> here: [1]https://www.bestpractical.com/docs/rt/4.2.9/extending/external_custom_fields.html.
> We are providing both the 'name' and 'description' in the returned result.
> We are using the custom field in our tickets.
> We wish to have the 'description' field provided by our external source
> displayed in the select element on the ticket form and the 'name' field
> stored in the database, however only the name field is being displayed.
> Is it possible to show the description field in the select box and store
> the name field in the database if it is selected? Or is this working as
> intended?
it's working as intended, but if you have a bit of perl knowledge, you
should be able to quickly add the description in
share/html/Elements/EditCustomFieldSelect.
example:
- ><% $name %></option>
+ ><% ($value->Description) ? $value->Description : $value->Name %></option>
if you wan't to show the description on an already assigned field, you
have to add a "ContentDescription" method in
local/lib/RT/ObjectCustomFieldValue_Local.pm that will filter on the
current CF Name assigned to object and get Description from CF values.
Something like:
------ snip ------
package RT::ObjectCustomFieldValue;
use strict;
no warnings qw(redefine);
sub ContentDescription {
my $self = shift;
my $content = $self->Content;
if ( grep { $self->CustomFieldObj->Type eq $_ } qw( Select Combobox ) ) {
my $Values = $self->CustomFieldObj->Values;
$Values->Limit( FIELD => 'Name', VALUE => $content );
if ( $Values->Count && $Values->Count == 1 ) {
my $Value = $Values->First;
$content = ( $Value->Description ) ? $Value->Name.' ('.$Value->Description.')' : $Value->Name;
}
}
return $content;
}
1;
------ snip ------
Then use this method mainly in share/html/Elements/ShowCustomFields.
- $m->out( $m->interp->apply_escapes( $value->Content, 'h' ) );
+ $m->out( $m->interp->apply_escapes( $value->ContentDescription, 'h' ) );
Be warned that if you deleted a value in the CF, matching objects will
not be able to find the matching Description.
--
Easter-eggs Spécialiste GNU/Linux
44-46 rue de l'Ouest - 75014 Paris - France - Métro Gaité
Phone: +33 (0) 1 43 35 00 37 - Fax: +33 (0) 1 43 35 00 76
mailto:elacour at easter-eggs.com - http://www.easter-eggs.com
More information about the rt-devel
mailing list