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>



---------
RT 4.4 and RTIR Training Sessions https://bestpractical.com/training
* Washington DC - May 23 & 24, 2016

Reply via email to