Adding Asset to Ticket by Name

Hi - I just set up a test server of RT 5.0 using data from our long-running 4.4 system. I’m trying to fix some issues with assets.

When you link an asset to an existing ticket, I cannot seem to get the search box to find assets by anything but ID number. I am talking about the field inside the ticket display:

I have tried using the AssetSearchFields setting thus:

Set($AssetSearchFields, {
Name        => 'LIKE',

However, I still get an error when entering anything but an asset ID.

Also, when I create a new ticket in a queue that is a member of “AssetQueues”, I get an Asset box but no search option:

Please note that these are not new issues to 5.0, I was just hoping they’d been fixed. Any insight and help would be appreciated.

I don’t think this is a bug as much as a feature request. That being said it looks like when an asset gets submitted to the display page it only expects ID. If you’re willing to hack around a bit its probably not too complicated to implement this

Actually its quite easy to add an autocomplete option that still uses ID.


diff --git a/share/html/Ticket/Elements/ShowAssets b/share/html/Ticket/Elements/ShowAssets
index bebb094ec..441ccd257 100644
--- a/share/html/Ticket/Elements/ShowAssets
+++ b/share/html/Ticket/Elements/ShowAssets
@@ -213,7 +213,7 @@ if ($ShowRelatedTickets) {
     <label><&|/l&>Add an asset to this ticket:</&></label>
     <div class="form-row">
       <div class="form-group mx-sm-3 mb-2">
-        <input class="form-control mb-2" size="10" name="<% $Ticket->id %>-RefersTo" placeholder="<&|/l&>Asset #</&>" type="text">
+        <input data-autocomplete="Assets" class="form-control mb-2" size="10" name="<% $Ticket->id %>-RefersTo" placeholder="<&|/l&>Asset #</&>" type="text">
       <button type="submit" name="AddAsset" value="Add" class="button btn btn-primary form-control mb-2">Add</button>
diff --git a/share/static/js/autocomplete.js b/share/static/js/autocomplete.js
index c56ea3321..1744aacb1 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -7,7 +7,8 @@ window.RT.Autocomplete.Classes = {
     Groups: 'group',
     Tickets: 'tickets',
     Queues: 'queues',
-    Articles: 'articles'
+    Articles: 'articles',
+    Assets: 'Assets'

 Selectize.define('rt_drag_drop', function(options) {

New file local/html/Helpers/Autocomplete/Assets:

% $r->content_type('application/json; charset=utf-8');
<% JSON( \@suggestions ) |n %>
% $m->abort;
$term       => undef
$max        => 10
$op         => 'STARTSWITH'
$right      => undef
$return     => 'id'
$queue      => undef
# Only allow certain return fields
$return = 'Name'
    unless $return =~ /^(?:id|Name)$/;

$m->abort unless defined $return
             and defined $term
             and length $term;

# Sanity check the operator
$op = 'STARTSWITH' unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;

my $assets = RT::Assets->new( $session{CurrentUser} );

$assets->RowsPerPage( $max );
    FIELD           => 'Name',
    OPERATOR        => $op,
    VALUE           => $term,

my @suggestions;
while (my $a = $assets->Next) {
    next if $right and not $a->CurrentUserHasRight($right);
    my $value = $a->$return;
    push @suggestions, { label => $a->Name, value => $value };

I just copied the articles autocomplete file and changed the search to assets

1 Like

I really appreciate the patch and will totally try this out. I guess I am misunderstanding the “AssetSearchFields” variable? We actually solved this issue with a little Chrome plugin in 4.4.4. However, I’m also still wondering why, when creating a new ticket, I just get a blank Asset section and not even a search field?

Thanks again for the really quick response!

I’m not sure the reason ( maybe it just wasn’t a feature that was able to get in? ) but adding the autocomplete brings it close. It’d be nice to track down where the link is checked for if its an asset and have that be able to accept a name or an ID

1 Like