Show Ticket Message in Search/Results.html

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.

local/html/Elements/CollectionList

ticket_preview.txt (2 KB)

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.

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@easter-eggs.com - http://www.easter-eggs.com

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. :slight_smile:

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>

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

You should see in your logs a message like ‘function TicketPreview not
defined’ …

$ cat local/lib/rt/Ticket_Local.pm

because the correct path is local/lib/RT/Ticket_Local.pm

Chris

I tried that already and it didnt change a thing.

I run the dev server directly form the command line (./sbin/rt-server
–port 3000) and dont get an error msg.

Another path that looks weird to me is:

“local/Callbacks/YourOrg/Elements/RT__Ticket/ColumnMap/Once”

shouldnt that be

“local/Callbacks/YourOrg/Elements/RT/Ticket/ColumnMap/Once”

?On 25.04.2016 07:59, Christian Loos wrote:

Am 23.04.2016 um 10:25 schrieb David Schmidt:

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

You should see in your logs a message like ‘function TicketPreview not
defined’ …

$ cat local/lib/rt/Ticket_Local.pm

because the correct path is local/lib/RT/Ticket_Local.pm

Chris

Another path that looks weird to me is:

“local/Callbacks/YourOrg/Elements/RT__Ticket/ColumnMap/Once”

shouldnt that be

“local/Callbacks/YourOrg/Elements/RT/Ticket/ColumnMap/Once"
Arg … I missed this, this must be
"local/html/Callbacks/YourOrg/Elements/RT__Ticket/ColumnMap/Once”

Chris

Am 25.04.2016 um 08:46 schrieb David Schmidt:

Another path that looks weird to me is:

“local/Callbacks/YourOrg/Elements/RT__Ticket/ColumnMap/Once”

shouldnt that be

“local/Callbacks/YourOrg/Elements/RT/Ticket/ColumnMap/Once"
Arg … I missed this, this must be
"local/html/Callbacks/YourOrg/Elements/RT__Ticket/ColumnMap/Once”

Chris

Hey Chris, thanks for your help.

After a bit of debugging these appear to be the correct locations:

“local/html/Callbacks/Univie/Search/Elements/BuildFormatString/Default”
“local/html/Callbacks/Univie/Elements/RT__Ticket/ColumnMap/Once”
“local/lib/RT/Ticket_Local.pm”

I’ll wrap everything up in an extension and put it on github.

cheers
david

Am 25.04.2016 um 08:46 schrieb David Schmidt:

Another path that looks weird to me is:

“local/Callbacks/YourOrg/Elements/RT__Ticket/ColumnMap/Once”

shouldnt that be

“local/Callbacks/YourOrg/Elements/RT/Ticket/ColumnMap/Once"
Arg … I missed this, this must be
"local/html/Callbacks/YourOrg/Elements/RT__Ticket/ColumnMap/Once”

Chris

Hey Chris, thanks for your help.

After a bit of debugging these appear to be the correct locations:

“local/html/Callbacks/Univie/Search/Elements/BuildFormatString/Default”
“local/html/Callbacks/Univie/Elements/RT__Ticket/ColumnMap/Once”
“local/lib/RT/Ticket_Local.pm”

I’ll wrap everything up in an extension and put it on github.

cheers
david

RT 4.4 and RTIR Training Sessions https://bestpractical.com/training

  • Washington DC - May 23 & 24, 2016

Sorry, late to the conversation, but here’s something I think is similar:

https://metacpan.org/pod/RT::Extension::PreviewInSearchOn 4/25/16 4:48 AM, David Schmidt wrote:

On 25.04.2016 09:58, David Schmidt wrote:

On 25.04.2016 08:49, Christian Loos wrote:

Am 25.04.2016 um 08:46 schrieb David Schmidt:

Another path that looks weird to me is:

“local/Callbacks/YourOrg/Elements/RT__Ticket/ColumnMap/Once”

shouldnt that be

“local/Callbacks/YourOrg/Elements/RT/Ticket/ColumnMap/Once"
Arg … I missed this, this must be
"local/html/Callbacks/YourOrg/Elements/RT__Ticket/ColumnMap/Once”

Chris

Hey Chris, thanks for your help.

After a bit of debugging these appear to be the correct locations:

“local/html/Callbacks/Univie/Search/Elements/BuildFormatString/Default”
“local/html/Callbacks/Univie/Elements/RT__Ticket/ColumnMap/Once”
“local/lib/RT/Ticket_Local.pm”

I’ll wrap everything up in an extension and put it on github.

cheers
david

RT 4.4 and RTIR Training Sessions https://bestpractical.com/training

  • Washington DC - May 23 & 24, 2016

https://github.com/davewood/RT-Extension-TicketPreview

RT 4.4 and RTIR Training Sessions https://bestpractical.com/training

  • Washington DC - May 23 & 24, 2016