[rt-users] Special Custom Field Display/Edit - Suggestions?

Todd Chapman todd at chaka.net
Thu Nov 15 13:51:57 EST 2007


RT has a callback that lets you override the name of the component
that is used to render the custom field. We use this to turn an input
CF into a select CF that is loaded with values from an RPC call. Here
is the callbacK:

> cat /opt/rt3/local/html/Callbacks/myCompany/Elements/EditCustomField/EditComponentName

<%INIT>
return unless $CustomField;

if ( $CustomField->FriendlyPattern =~ /\WTime\W/ ) {
    $$Name = $m->callers(1)->dir_path . "/CustomFields/TimePicker";
    return;
}

my
$Comp = $CustomField->Name;
$Comp =~ s/\W/_/g;
$Comp = $m->callers(1)->dir_path . "/CustomFields/EditCF_$Comp";

$$Name = $m->comp_exists($Comp.$CustomField->id) ? $Comp.$CustomField->id
       : $m->comp_exists($Comp)                  ? $Comp
       : $$Name;
</%INIT>
<%ARGS>
$Name
$CustomField => undef
$Object => undef
</%ARGS>


This allows us to create files in
/opt/rt3/local/html/Elements/CustomFields. For example:

> cat /opt/rt3/local/html/Elements/CustomFields/EditCF_Client_Name39
%       my $id = $NamePrefix . $CustomField->Id;

<select name="<%$id%>-Values" id="<%$id%>-Values" size="10" >
        <option value="" >(no value)</option>
% if ( @$clients == 1 ) {
    <option value="<%$Values->First->Content%>" SELECTED >
     <%$Values->First->Content%>
    </option>
% }
% for my $client ( @$clients ) {
%   my $value = $client->{client_id} || $client->{client_name};
    <option value="<%$value%>" <% $Values && $Values->HasEntry($value)
? 'SELECTED' : ''%> >
        <%substr($client->{client_name}, 0, 50)%>
    </option>
% }
</select>

<%init>
my $clients = myCompany::RPC->get_clients();
</%init>

<%args>
$Object => undef
$CustomField => undef
$NamePrefix => undef
$Default => undef
$Values => undef
$Multiple => 0
$Rows => undef
</%args>



-Todd

On 11/15/07, Todd Williams <willir70 at gmail.com> wrote:
> Has anyone else had success with this Custom Custom Field idea and
> have any sample implementations they might be willing to share?  I've
> read through the RT Wiki pages on customizing RT but I am not sure
> where to start with this.  I have not seen any reference information
> posted anywhere doing what we are trying to do here.  Sorry if I'm
> missing something obvious, just not seeing it.
>
> Any guidance, samples, or otherwise pointers to more detailed
> information on what we need to do to effectively implement a
> customized Custom Field would be extremely helpful.
>
> Thanks in advance!
>
> On Nov 1, 2007 5:50 AM, Stan Sawa <stanislaw.sawa at uk.clara.net> wrote:
> > On Tue, 30 Oct 2007 11:51:34 -0400
> > "Todd Williams" <willir70 at gmail.com> wrote:
> > > Has anyone done anything similar to this?  Can anybody offer some
> > > pointers, ideas, or thoughts?  Any suggestions would be greatly
> > > appreciated.
> > >
> >
> >
> > we are currently implementing something like this (that is special
> > customfield with customised editor viewer). Approach, which seems to
> > work quite fine is adding new type of custom field (which will be used
> > only in one cf, but it gives us nice separation of code):
> >
> > % cat local/lib/RT/CustomField_Local.pm
> > no warnings qw/redefine/;
> > package RT::CustomField;
> >
> > $FieldTypes{ClCustID} = [
> >     'Select multiple customers',
> >     'Select one customer'
> > ];
> >
> > then, we create/add custom field to queue(s). As rt is using custom
> > field type for selecting which widget/componenet, so it is using:
> >
> > local/html/Elements/EditCustomFieldClCustID
> > local/html/Elements/ShowCustomFieldClCustID
> >
> > they were created based on one of default ones, with added additional
> > 'helper' dropdowns and searches. They use some javascript/async
> > requests to fetch data from other systems and modify existing controls.
> > The only thing you have to keep in mind is that the value stored in
> > customfield is the one which is passed in
> > '<%$NamePrefix.$CustomField->Id%>-Value' field of form, so you have to
> > make sure it is filled with correct value.
> >
> > Hope it helps.
> >
> > --
> > Stanislaw Sawa
> > _______________________________________________
> > http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
> >
> > SAVE THOUSANDS OF DOLLARS ON RT SUPPORT:
> >
> > If you sign up for a new RT support contract before December 31, we'll take
> > up to 20 percent off the price. This sale won't last long, so get in touch today.
> >     Email us at sales at bestpractical.com or call us at +1 617 812 0745.
> >
> >
> > Community help: http://wiki.bestpractical.com
> > Commercial support: sales at bestpractical.com
> >
> >
> > Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
> > Buy a copy at http://rtbook.bestpractical.com
> >
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
> SAVE THOUSANDS OF DOLLARS ON RT SUPPORT:
>
> If you sign up for a new RT support contract before December 31, we'll take
> up to 20 percent off the price. This sale won't last long, so get in touch today.
>     Email us at sales at bestpractical.com or call us at +1 617 812 0745.
>
>
> Community help: http://wiki.bestpractical.com
> Commercial support: sales at bestpractical.com
>
>
> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
> Buy a copy at http://rtbook.bestpractical.com
>



More information about the rt-users mailing list