[rt-users] How to search update/comment fields and link an asset if its mentioned?

Todd Chapman todd at chaka.net
Thu Jul 9 17:03:04 EDT 2009


Brett,

I would look at the ExtractCustomFields extension to see how it search
the ticket. However your job is much harder because you have to
recognize all asset names, unless you require the asset be referred to
with a specific format, could make it a bit easier.

-Todd

On Thu, Jul 9, 2009 at 4:35 PM, Brett Spedale<brett at precisionmobile.net> wrote:
> Hey guys,
>
> I'm using Request Tracker 3.8.4 and Asset Tracker 1.2.4 on a Debian Etch
> box. RTFM 2.4.2 is also installed.
>
> When a ticket is created/updated/resolved, I'm trying to search the
> contents of the ticket for an asset's hostname. If the hostname is
> mentioned in the ticket, then I'd like for a bidirectional link to
> automatically be created between the ticket and the asset.
>
> I've downloaded and installed the LinkTicketToAsset scrip, and it works
> great for what it was intended for -- whenever I enter an asset's
> hostname in the "Asset" custom field, it will create a bidirectional
> link between the asset and the ticket. However, I can't figure out how
> to modify it to search the entire contents of the ticket, or at least
> the comment/reply/resolve sections (the main text sections).
>
> Here is the custom condition of the LinkTicketToAsset scrip:
>
> my $trans = $self->TransactionObj->Type;
> my $new_value = $self->TransactionObj->NewValue;
> my $cf_id = $self->TransactionObj->Field;
>
> if ($trans ne 'CustomField') { return 0; }
> if (! $new_value) { return 0; }
> my $cf = new RT::CustomField($RT::SystemUser);
> my ($id,$msg) = $cf->Load($cf_id);
>
> if (!$id) {
>   $RT::Logger->crit("Could not load CF: $msg");
>   return 0;
> }
> if ($cf->Name ne 'Asset') { return 0; }
>
> 1;
>
>
> Here is the cleanup code:
>
> my $new_value = $self->TransactionObj->NewValue;
> my $asset = RTx::AssetTracker::Asset->new($self->CurrentUser);
> my ($id,$msg) = $asset->Load($new_value);
> if (! $id) {
>   $RT::Logger->crit("Could not load asset $new_value: $msg");
>   return 0;
> }
> ($id,$msg) = $self->TicketObj->AddLink(Type => 'RefersTo', Target =>
> $asset->URI);
> if (! $id) {
>   $RT::Logger->crit("Could not AddLink: $msg");
>   return 0;
> }
> 1;
>
>
> I'm brand new to Asset Tracker scrips so I'm having trouble
> understanding what I would need to change to get this scrip to work by
> searching the entire ticket instead of just the Asset custom field. I
> see where the Asset custom field is mentioned, but I'm not sure what to
> replace it with.
>
> Any help or recommendations on where to begin would be appreciated.
>
> Thanks!
>
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
> Community help: http://wiki.bestpractical.com
> Commercial support: sales at bestpractical.com
>
>
> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
> Buy a copy at http://rtbook.bestpractical.com
>



More information about the rt-users mailing list