Adding an editable column with callback `RT__Ticket/ColumnMap/Once`

Hi everybody,
I’m trying to add a Merge into column into a saved search using callback RT__Ticket/ColumnMap/Once. Here is the code:

<%init>
use strict;
use warnings;
use utf8;
## Once
$COLUMN_MAP->{'MergeInto'} = {
    attribute => 'MergeInto',
    title     => loc('Merge into'), # loc
    align     => 'left',
    value     => sub { 
        my $Ticket = shift;
        return \( '-' ) unless ( $Ticket );
        return \( '-' ) unless ( ref $Ticket );
        return \( sprintf( '<span>%d</span>', $Ticket->EffectiveId ) );
    },
    edit => sub { 
        my $Ticket = shift;
        return unless ( $Ticket );
        return unless ( ref $Ticket );
        return \( '<input type="text" class="form-control" name="'. $Ticket->id .'-MergeInto" value="" data-autocomplete="Tickets" data-autocomplete-exclude="' . $Ticket->id . '" />' );
    }
};

</%init>
<%args>
$COLUMN_MAP => undef
</%args>

Its adding a column title Merge into, but nothing more.

The question is: What I'm doing wrong?
Hints, advises are appreciated.

Thanks, Peter

1 Like

Sorry, it was my bad: I put my callback in wrong place.
it should be Elements/RT__Ticket/ColumnMap/Once.

Thnx

Hi @Peter_Petky

Does it work?

I tried to put in some html this way and failed.

share/html/Elements/CollectionAsTable/Row says at line 147ff

    $m->out(qq{<td class="$class" });

    $m->out( $_ .'="'. $m->interp->apply_escapes( $attrs{$_} => 'h' ) .'"' )
        foreach grep $attrs{$_}, qw(align style colspan);

    $m->out('>');
    $m->out(@out) if @out;
    $m->out( '</td>' . "\n" );

what in my readings it prints the value as html-escaped text. So you never get the input-fields but can read what you wanted to do :slight_smile:

Assumable it can only be done with javascript or like this.

regards, A.

Hi, short answer – yes.
Longer answer: put the file Once in local/html/Callbacks/Misc/Elements/RT__Ticket/ColumnMap/

<%init>
use strict;
use warnings;
use utf8;
## Once
$COLUMN_MAP->{'MergeInto'} = {
    attribute => 'MergeInto',
    title     => loc('Merge into'), # loc
    align     => 'left',
    value     => sub { return \( '<span></span>' ) },
    edit      => sub { 
        return \( '<input type="text" class="form-control" name="'. $_[0]->id .'-MergeInto" value="" data-autocomplete="Tickets" data-autocomplete-exclude="' . $_[0]->id . '" />' );
    }
};

</%init>
<%args>
$COLUMN_MAP => undef
</%args>

Than you may put MergeInto in Search Format:

'<a href="__WebPath__/Ticket/Display.html?id=__id__">__id__</a>/TITLE:#',
'<a href="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a>/TITLE:Subject',
QueueName,
ExtendedStatus,
Created,
Due,
MergeInto,
'<a href="__WebPath__/Ticket/Display.html?Action=Take&amp;id=__id__">__loc(Take)__</a>/TITLE:NBSP'

BRG, Peter

Thank you @Peter_Petky, made my day.

We use rt4.4.7 so edit is not availiable. But with your code I found my fault for view, I was lost in pointers. Now view with html-tags works for me, too.

Maybe you know already: To get your Merge into availiable in dropdown at the query-builder you need to define it:

File: local/html/Callbacks/Misc/Search/Elements/BuildFormatString/Default

<%INIT>
  push @{$Fields}, 'MergeInto';
</%INIT>
<%ARGS>
  $Fields => undef
</%ARGS>

BR andre.