[rt-users] Show Ticket Message in Search/Results.html

David Schmidt david.schmidt at univie.ac.at
Sat Apr 23 04:25:03 EDT 2016


On 21.04.2016 15:56, Emmanuel Lacour wrote:
> Le 21/04/2016 15:12, David Schmidt a écrit :
>> When I list tickets I want to show the first 3 lines of the ticket
>> message for each ticket.
>> 
>> I am using the following patch to achieve this, but it is quite a 
>> hack.
>> Can someone recommend a cleaner solution.
>> 
>> 
> 
> 
> you don't have to patch, you can use the callback "Once" in
> Elements/RT__Ticket/ColumnMap
> 
> so just create a file
> local/Callbacks/YourOrg/Elements/RT__Ticket/ColumnMap/Once
> 
> with a content that will ad such column.
> 
> Something like:
> 
> <%init>
> $COLUMN_MAP->{First3Lines} = {
>     title => 'First3Lines',
>     value => sub { return loc($_[0]->First3Lines) }
> };
> 
> </%init>
> <%args>
> $COLUMN_MAP => undef
> $GenericMap => undef
> </%args>
> 
> 
> 
> And in a local/lib/rt/Ticket_Local.pm:
> 
> package RT::Ticket;
> 
> use strict;
> no warnings qw(redefine);
> use utf8;
> 
> sub First3Lines {
>     my $self = shift;
> 
>     [your code here]
> 
>     return $content;
> }
> 
> 1;
> 
> 
> Then another callback to make this new "First3Lines" available as a
> columns in the search builder:
> 
> local/Callbacks/YourOrg/Search/Elements/BuildFormatString/Default
> <%init>
> push @$Fields, 'First3Lines';
> </%init>
> <%args>
> $Fields => undef
> </%args>
> 
> 
> 
> 
> this way, you don't have to patch and your changes should stay as is
> from rt versions to rt versions.


Hello Emmanuel,

this sounds like solid advice, thank you very much.

I wrote the following code following your example but it seems there is 
an error somewhere.

"TicketPreview" shows up in the Search/Results.html table but the cell 
is empty for each row.

On a sidenote (and without intention to blame you for anything) RT 
development is horrible to debug. :)

I attached 2 screenshots.

$ cat local/Callbacks/Univie/Elements/RT__Ticket/ColumnMap/Once
<%init>
$COLUMN_MAP->{TicketPreview} = {
     title => 'TicketPreview',
     value => sub { return loc($_[0]->TicketPreview) }
};
</%init>
<%args>
$COLUMN_MAP => undef
$GenericMap => undef
</%args>


$ cat local/lib/rt/Ticket_Local.pm
package RT::Ticket;
use strict;
use warnings;
sub TicketPreview {
     my $self = shift;
     my $content = 'foobar';
     return $content;
}
1;


$ cat local/Callbacks/Univie/Search/Elements/BuildFormatString/Default
<%init>
push @$Fields, 'TicketPreview';
</%init>
<%args>
$Fields => undef
</%args>



-------------- next part --------------
A non-text attachment was scrubbed...
Name: SearchBuilder.png
Type: image/png
Size: 24882 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20160423/00c71e1f/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SearchResults.png
Type: image/png
Size: 26769 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20160423/00c71e1f/attachment-0001.png>


More information about the rt-users mailing list