Wikia

Request Tracker Wiki

DisplayCustomFieldsInTicketSearch

Comments0
858pages on
this wiki

Custom Fields in Ticket Search Results Edit

4.0 Edit

Use __CustomField.{NAME}__ as field name to display custom field values in search results.

Example: '__Status__', '__CustomField.{customerid}__', '__OwnerName__',

Older Edit

/* Note: this section "custom fields in ticket search results" doesn't seem to apply to RT 3.6 and above ... */

Copy [=rt/share/html/Search/Elements/TicketRow] and [=rt/share/html/Search/Elements/TicketHeader] to your rt/local/html directory. Be sure to duplicate the directory structure.

In TicketRow add the following to include the value of the "SubQueue" custom field:

[=$Ticket->FirstCustomFieldValue('SubQueue')]

You can replace an existing column or add a new column. In either case, you'll need to adjust the column headings in [=rt/local/html/Search/Elements/TicketHeader] appropriately. Here's another example

<TD><small><%$Ticket->FirstCustomFieldValue('Department')%>
<%$Ticket->Requestors->MemberEmailAddressesAsString%></small></td>

Customizing the Ticket Search Results Edit

See the DefaultSearchResultFormat option in the etc/RT_Config.pm configuration file for ways to customize the ticket search results page. If you edit this setting, you should do so in the SiteConfig file.

Ensuring Custom Fields are sortable in the !TicketHeader Edit

/todo/

Custom Fields in the "At a Glance" Ticket Summary Edit

RT 3.6.3 Edit

See ChangeDefaultRTAtAGlance

RT 3.4.x Edit

If you would like to add custom fields to the opening ticket summary page, then copy [=rt/share/html/Elements/MyTickets] to [=rt/local/html/Elements/MyTickets] and edit MyTickets in a similar fashion.

A novice user writes: In my small experience with RT 3.2.x, the key line in [=MyTickets] to examine and edit is the "Format = >" line. This is the line that controls what appears in the listing. Values are comma-separated and any text you want to to be used in the Title bar should be prefaced with "/Title:". In my case, I wanted to insert the value of a custom field called "SupportLevel" into the "At A Glance" Ticket Summary. The specific text I inserted into the Format line was simply: [='CustomField.SupportLevel /TITLE:Level']. To make this consistant on the entire "At A Glance" page I made the same edit to the [=MyRequests] file.

Note: I had to learn the hard way, that for RT3.4.x at least, the syntax is "CustomField.{CustomFieldName}", e.g., for the above example you would enter [='CustomField.{SupportLevel}/TITLE:Level']. Many thanks to Filip Jonckers for finally enlightening me.

*

To display other columns, you can lookup the names of the ones that come with RT3.4 here: cat RTROOT/share/html/Elements/RT__Ticket/ColumnMap.

*

Once you've made these changes, you may have to restart your webserver software. For example, with Apache you would run 'apachectl graceful'.

Display Custom Fields with Custom Formatting Edit

by Graham Briggs

Unlike normal fields where you can easily override the subroutine that displays the field in ColumnMap, altering the formatting of a custom field is a little more awkward as far as I can see.

How I did it is as follows:

First step was to override the ColumnMap file. Copy the file from:

$RT_HOME/share/html/Elements/RT__Ticket/ColumnMap

into

$RT_HOME/local/html/Elements/RT__Ticket/ColumnMap

I added the following subroutine:

sub _compress {
  my $field = shift;
  my $ticket = shift;
  my $tring = "<div class=\"" . lc $field;

  if ($ticket->CustomFieldObj->Type eq "Select") {
    my $foo = lc $ticket->Content;
    $foo =~ s/[\W]//g;
    $tring .= $foo;
  }

  $tring .= "\">";

  if ($ticket->CustomFieldObj->Type eq 'Image') {
    $tring .= $m->scomp( '/Elements/ShowCustomFieldImage', Object => $ticket );
  } else {
    $tring .= $ticket->Content;
  }

  $tring .= "</div>";
  return $tring;
}

and edited the code within sub ColumnMap:

elsif ( $attr eq 'value' ) {
  return sub {
    my $values = $_[0]->CustomFieldValues($field);
    return map {
      \(_compress($field, $_)),
    } @{ $values->ItemsArrayRef };
  };
}

this alters the output to show <div class="fieldfoofoo">Foo Foo</div> instead of just "Foo Foo".

For a custom field named "Progress" and content "Pending Design Review" this will be <div class="progresspendingdesignreview">Pending Design Review</div>

Then you override the CSS file webrt.css - create a file called:

$RT_HOME/local/html/Callbacks/MyCallbacks/NoAuth/webrt.css/Default

and add in the CSS into that file. For example:

.progressnew {
  background-color: #ffffff;
}

.progressintegrationtesting {
  background-color: #00ff00;
}

.progresscompleted {
  background-color: #888888;
}

Which assigned pretty background colours to each status when printed, which is exactly what I wanted.

You can also redefine CSS elements in the rest of the page in this file, if you want to.


Minor changes for RT 4.0.8:Edit

By Daniel Farst

I edited the subroutine from Graham to also have binary file custom fields (Upload One File, Upload Multiple Files) display as links to the actual file rather than just a file name (much more useful in my opinion). Remove the elsif Type eq Binary stanza if you don't want it. This also changes the div class to remove spaces from the field names and adds a second class with just the fieldname and no value:

my $_compress = sub {
  my $field = shift;
  my $ticket = shift;
  
  $field =~ s/\s//g;
  
  my $tring = "<div class=\"CF-" . lc $field;
  $tring .= " CF-" . lc $field . "-";

  if ($ticket->CustomFieldObj->Type eq "Select") {
    my $foo = lc $ticket->Content;
    $foo =~ s/[\W]//g;
    $tring .= $foo;
  }

  $tring .= "\">";

  if ($ticket->CustomFieldObj->Type eq 'Image') {
    $tring .= $m->scomp( '/Elements/ShowCustomFieldImage', Object => $ticket );
  } elsif ($ticket->CustomFieldObj->Type eq 'Binary') {
    $tring .= $m->scomp( '/Elements/ShowCustomFieldBinary', Object => $ticket );
  } else {
    $tring .= $ticket->Content;
  }
  
  $tring .= "</div>";
  return $tring;
};

Copy and paste the above sub into the ColumnMap file immediately below

my $COLUMN_MAP;

Add the below part to the ColumnMap variable

CustomField => {
    attribute => sub { return shift @_ },
    title     => sub { return pop @_ },
    value     => sub {
        # Display custom field contents, separated by newlines.
        # For Image custom fields we also show a thumbnail here.

        my $values = $_[0]->CustomFieldValues( $_[-1] );
        my @values = map {
            \($_compress->( $_[-1] , $_ )),
            \'<br />',
            } @{ $values->ItemsArrayRef };
        pop @values; # Remove that last <br />
        return @values;
        },
    },

In RT, Naivgate to Tools -> Configuration -> Tools -> Theme and edit the Custom CSS in the advanced box. This will give <div class="CF-fieldname CF-fieldname-value">Value</div> for Custom Field Field Name -> Value

Bugs Edit

At least RT version 3.0.9 has a bug which prevents the above from working. Instead of the custom field name, only the custom field id will work. So [=$Ticket->FirstCustomFieldValue('SubQueue')] would become [=$Ticket->FirstCustomFieldValue('2')]. RT 3.0.10 fixes this though.

A nasty (nasty because without the counter it keeps looping, and also nasty because I have no knowledge of RT guts and hadn't even read this page when I wrote this) hack for 3.0.9 involves making a hash of field names with id numbers so that the names can be used:

Around Wikia's network

Random Wiki