How to search update/comment fields and link an asset if its mentioned?

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!

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.

-ToddOn Thu, Jul 9, 2009 at 4:35 PM, Brett Spedalebrett@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!


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Todd (and others),

Thanks, I’m looking through ExtractCustomFields and trying to figure out
what’s going on. I do have a very specific name format for the assets so
it shouldn’t be too bad.

I’ve realized that I’m not going to be able to figure this out
immediately. Are there any good resources for learning how to create
complex scrips? Does the O’Reilly book on RT have any sections on this?

Thanks again,
BrettOn Thu, 2009-07-09 at 17:03 -0400, Todd Chapman wrote:

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 Spedalebrett@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!


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com