Using custom conditions with custom fields

Hi all,

I have what would seem to be a fairly typical situation here. I’ve got
a certain queue with two custom fields for each ticket contained there.
Let’s call the custom fields “Foo” and “Bar.” I would like to trigger a
scrip when the value of the “Foo” custom field is set to “Baz.” I’ve got
the following custom condition for my scrip (adapted from the wiki):

if ( ($self->TransactionObj->Type eq “CustomField” ||
$self->TransactionObj->Type eq “Create” ) &&
($self->TicketObj->FirstCustomFieldValue(‘Foo’) =~ /Baz/i) ) {
return 1;
}
return 0;

This doesn’t quite work because it also gets triggered when the “Bar”
custom field is modified. I only want this to run when “Foo” is set to
“Baz” regardless of the value of “Bar” and whether it was changed.

It would seem that I need a way to have the scrip ignore changes to
custom fields other than “Foo.” Is this possible?

-Tim

Tim Wilson, Director of Technology
Buffalo-Hanover-Montrose Schools
214 1st Ave NE Buffalo, MN 55313
ph: 763.682.8740 fax: 763.682.8743 http://www.buffalo.k12.mn.us

Hi all,

I have what would seem to be a fairly typical situation here. I’ve got
a certain queue with two custom fields for each ticket contained there.
Let’s call the custom fields “Foo” and “Bar.” I would like to trigger a
scrip when the value of the “Foo” custom field is set to “Baz.” I’ve got
the following custom condition for my scrip (adapted from the wiki):

if ( ($self->TransactionObj->Type eq “CustomField” ||
$self->TransactionObj->Type eq “Create” ) &&
($self->TicketObj->FirstCustomFieldValue(‘Foo’) =~ /Baz/i) ) {
return 1;
}
return 0;

This doesn’t quite work because it also gets triggered when the “Bar”
custom field is modified. I only want this to run when “Foo” is set to
“Baz” regardless of the value of “Bar” and whether it was changed.

It would seem that I need a way to have the scrip ignore changes to
custom fields other than “Foo.” Is this possible?

$self->TransactionObj->Field has the Id of the custom
field being changed.

So you would have:

unless (
( $self->TransactionObj->Type eq “CustomField”
&& $self->TransactionObj->Field == $my_id )
|| $self->TransactionObj->Type eq “Create”
) {
return 0;
}

return 0 unless $self->TicketObj->FirstCustomFieldValue(‘Foo’) =~ /Baz/i;

1;

Todd (and others),

Thanks for the help. That makes sense to me except for one thing. I’m
not sure where the $my_id comes from. More precisely, I don’t see how
comparing $self->TransactionObj->Field to $my_id works in this case. I
realize this isn’t a perl tutorial list, but I’m puzzled.

-Tim

Tim Wilson, Director of Technology
Buffalo-Hanover-Montrose Schools
214 1st Ave NE Buffalo, MN 55313
ph: 763.682.8740 fax: 763.682.8743 http://www.buffalo.k12.mn.us

Todd Chapman todd@chaka.net 12/22/06 4:56 PM >>>

Hi all,

I have what would seem to be a fairly typical situation here. I’ve got
a certain queue with two custom fields for each ticket contained
there.
Let’s call the custom fields “Foo” and “Bar.” I would like to trigger
a
scrip when the value of the “Foo” custom field is set to “Baz.” I’ve
got
the following custom condition for my scrip (adapted from the wiki):

if ( ($self->TransactionObj->Type eq “CustomField” ||
$self->TransactionObj->Type eq “Create” ) &&
($self->TicketObj->FirstCustomFieldValue(‘Foo’) =~ /Baz/i) ) {
return 1;
}
return 0;

This doesn’t quite work because it also gets triggered when the “Bar”
custom field is modified. I only want this to run when “Foo” is set to
“Baz” regardless of the value of “Bar” and whether it was changed.

It would seem that I need a way to have the scrip ignore changes to
custom fields other than “Foo.” Is this possible?

$self->TransactionObj->Field has the Id of the custom
field being changed.

So you would have:

unless (
( $self->TransactionObj->Type eq “CustomField”
&& $self->TransactionObj->Field == $my_id )
|| $self->TransactionObj->Type eq “Create”
) {
return 0;
}

return 0 unless $self->TicketObj->FirstCustomFieldValue(‘Foo’) =~
/Baz/i;

1;

Tim Wilson wrote:

Thanks for the help. That makes sense to me except for one thing. I’m
not sure where the $my_id comes from.

It’s the numerical ID of the custom field. As a superuser, go to
Configuration, Custom Fields and open the Foo custom field. Then look at
the URL in your web browser:

https://rt.example.com/Admin/CustomFields/Modify.html?id=NN

NN is the ID number of the custom field.

Rick R.

Todd (and others),

Thanks for the help. That makes sense to me except for one thing. I’m
not sure where the $my_id comes from. More precisely, I don’t see how
comparing $self->TransactionObj->Field to $my_id works in this case. I
realize this isn’t a perl tutorial list, but I’m puzzled.

-Tim

You have to do something like:

my $cf = RT::CustomField->new( $RT::SystemUser );
$cf->LoadByName( NAME => ‘my_cf’, QUEUE => ‘my_queue’ );
$cf->id;