RT3.8.7 using custom fields to restrict sending a reply on resolve

Hi,

I’m trying to implement a system so that if a custom field is set to
"Y", then the system will send an email (specified by a template) to
the requestor. If the CF is “N” or blank then it will not send, and
will simply resolve the ticket. I’ve borrowed from several other
sources such as
http://lists.bestpractical.com/pipermail/rt-users/2010-April/064498.html
and http://tpokorra.blogspot.com.au/2009/01/request-tracker-scrip-that-involves.html
but my end goal is a little different.

I’ve tried various combinations of things that I’ll describe in more
detail below, but the short version is that I cannot get it to
correctly send when CF=Y and not send when CF=N.

So far I have:

  • Created a template for the email (this part works OK - it looks
    correct when I test it)
  • Have created a scrip as follows on a test internal queue…

Description:SendFeedbackOnResolve
Condition: On Resolve
Action: AutoReply to Requestors
Template: MyCustomTemplate
Stage: TransactionCreate

Custom Condition:
my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;

if ($trans->Type eq ‘CustomField’)
{my $cf = new RT::CustomField($RT::SystemUser);
$cf->LoadByName(Queue => $ticket->QueueObj->id,Name => “RequestFeedback”);
return 0 unless $cf->id;
if ($trans->Field == $cf->id &&
$trans->NewValue eq “Y”)
{
return 1;
}
}
return 0;

This custom condition sends the email in every circumstance.
If I add Custom action preparation code: return 1; it does not appear
to change the behaviour
If I add Custom action cleanup code: return 1/0; it modifies the
behaviour as follows:
1 --> sends email
0 --> doesn’t send email

If I move that code to the action clean code block it always sends a message.

I’ve also tried with TransactionBatch instead of create, and action
"NotifyRequestors" but with no success.

Help! As you may have guessed I’m not a coder, so I’ve instead tried
to work through permutations to see how changing things impacts the
result… unfortunately none of it as desired :confused:

One thing that occured to me (but I don’t know how to do) is to change
the action to “User Defined” and then if the conditions are met, to
trigger an auto-reply with the desired template BUT I don’t know how
to do this…

Thanks in advance,

Chris

Chris,

Ever hear the term “Timing is everything”? I think your timing is off on
this. Your code is triggered by the transaction that changes the status to
“resolved”. Therefore, “New Value” will not be “Y”.

In your situation, I think your Custom Field already has a value of “Y” or
“N” and therefore there is no “New Value” being set for it.

What you need to do is look at the value that is already present in that
Custom Field.

Secondly, in your scrip you have already told RT to look for a standard
one, “On Resolve” and then you put user-defined custom code in the
condition area. That won’t work.

You need to change your Condition selection to “User-Defined”, then in the
Custom Condition code area you need to remove all the code you put in after
your definition of $trans and $ticket.

Then put in conditions like:

$cf_value = $ticket->whatever code defines the custom field;

if ($trans->Type->Status &&
$trans->NewValue eq “resolved” &&
$cf_value eq “Y”)
{
return 1;
}

return 0;

You’ll have to get the correct code to define the value in the ticket
custom field for your condition yourself as I’m out of state and not near
my computer, so I don’t have the code and I need my examples cause I’m not
much of a perl programmer.

However, this will simply specify your condition to be:

"if this current transaction is about the ticket being resolved AND
the value in the stated custom field is “Y”,

then continue, otherwise get out.

I think that is what you want.

I believe the RT wiki has an example or two of this, if not, my guide does.

Hope this helps.

Kenn

KennOn Mon, Feb 27, 2012 at 7:32 PM, Chris Herrmann chrisherrmann7@gmail.comwrote:

Hi,

I’m trying to implement a system so that if a custom field is set to
“Y”, then the system will send an email (specified by a template) to
the requestor. If the CF is “N” or blank then it will not send, and
will simply resolve the ticket. I’ve borrowed from several other
sources such as
[rt-users] How to detect a custom field change in a scrip
and
Diaries of a Programmer: Request Tracker scrip that involves the Category of a Custom Field
but my end goal is a little different.

I’ve tried various combinations of things that I’ll describe in more
detail below, but the short version is that I cannot get it to
correctly send when CF=Y and not send when CF=N.

So far I have:

  • Created a template for the email (this part works OK - it looks
    correct when I test it)
  • Have created a scrip as follows on a test internal queue…

Description:SendFeedbackOnResolve
Condition: On Resolve
Action: AutoReply to Requestors
Template: MyCustomTemplate
Stage: TransactionCreate

Custom Condition:
my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;

if ($trans->Type eq ‘CustomField’)
{my $cf = new RT::CustomField($RT::SystemUser);
$cf->LoadByName(Queue => $ticket->QueueObj->id,Name =>
“RequestFeedback”);
return 0 unless $cf->id;
if ($trans->Field == $cf->id &&
$trans->NewValue eq “Y”)
{
return 1;
}
}
return 0;

==============
This custom condition sends the email in every circumstance.
If I add Custom action preparation code: return 1; it does not appear
to change the behaviour
If I add Custom action cleanup code: return 1/0; it modifies the
behaviour as follows:
1 → sends email
0 → doesn’t send email

If I move that code to the action clean code block it always sends a
message.

I’ve also tried with TransactionBatch instead of create, and action
“NotifyRequestors” but with no success.

Help! As you may have guessed I’m not a coder, so I’ve instead tried
to work through permutations to see how changing things impacts the
result… unfortunately none of it as desired :confused:

One thing that occured to me (but I don’t know how to do) is to change
the action to “User Defined” and then if the conditions are met, to
trigger an auto-reply with the desired template BUT I don’t know how
to do this…

Thanks in advance,

Chris

RT Training Sessions (http://bestpractical.com/services/training.html)

  • Boston March 5 & 6, 2012

Thanks Ken, I have it working now. I also found
http://wiki-archive.bestpractical.com/view/CustomConditionSnippets
which was very helpful - it actually has a specific example for what
I’m trying to do. I have a couple of questions too… but first the
answer:

Condition: UserDefined
Action: NotifyRequestors
Template: MyTemplate
Stage: TransactionCreate

Custom Condition:
my $Ticket = $self->TicketObj;

We want the Request Feedback CF

my $TicketType = $Ticket->FirstCustomFieldValue(‘RequestFeedback’);

We want resolved status

return 0 unless $Ticket->Status eq “resolved”;

and… we want the CF to be Y

return 0 unless $TicketType eq ‘Y’;
return 1;

I tried a lot of different variations on the theme, along the lines of:
return 0 if $cf->$self->TicketObj->FirstCustomFieldValue(“RequestFeedback”)
eq “N”;
return 0 unless
$cf->$self->TicketObj->FirstCustomFieldValue(“RequestFeedback”) eq “Y”
return 0 unless
$cf->$self->TicketObj->FirstCustomFieldValue(‘RequestFeedback’) eq “Y”

but these didn’t return anything. I assume there’s a problem with my
syntax or how I’m referring to objects but couldn’t work it out…
luckily the page linked above has an example that has exactly what I’m
after!

In this case the scrip triggers if the ticket is reopened, then
resolved again - for us this is OK but for others they might want to
only trigger this condition the first time a ticket is resolved. I
think you would need to use another CF to record the result of the
transaction in this case (i.e. if successful then set
CF-SentFeedbackRequest=“y” or similar) and add an appropriate
condition to check above… but for us it’s not required.

Thanks!

Chris,

you’re welcome. The neat (and sometimes confusing for perl beginners like
me) thing is that with perl you can construct several different
styles/techniques of code that all do the same thing.

KennOn Mon, Mar 5, 2012 at 3:17 PM, Chris Herrmann chrisherrmann7@gmail.comwrote:

Thanks Ken, I have it working now. I also found
CustomConditionSnippets - Request Tracker Wiki
which was very helpful - it actually has a specific example for what
I’m trying to do. I have a couple of questions too… but first the
answer:

============================
Condition: UserDefined
Action: NotifyRequestors
Template: MyTemplate
Stage: TransactionCreate

Custom Condition:
my $Ticket = $self->TicketObj;

We want the Request Feedback CF

my $TicketType = $Ticket->FirstCustomFieldValue(‘RequestFeedback’);

We want resolved status

return 0 unless $Ticket->Status eq “resolved”;

and… we want the CF to be Y

return 0 unless $TicketType eq ‘Y’;
return 1;

I tried a lot of different variations on the theme, along the lines of:
return 0 if $cf->$self->TicketObj->FirstCustomFieldValue(“RequestFeedback”)
eq “N”;
return 0 unless
$cf->$self->TicketObj->FirstCustomFieldValue(“RequestFeedback”) eq “Y”
return 0 unless
$cf->$self->TicketObj->FirstCustomFieldValue(‘RequestFeedback’) eq “Y”

but these didn’t return anything. I assume there’s a problem with my
syntax or how I’m referring to objects but couldn’t work it out…
luckily the page linked above has an example that has exactly what I’m
after!

In this case the scrip triggers if the ticket is reopened, then
resolved again - for us this is OK but for others they might want to
only trigger this condition the first time a ticket is resolved. I
think you would need to use another CF to record the result of the
transaction in this case (i.e. if successful then set
CF-SentFeedbackRequest=“y” or similar) and add an appropriate
condition to check above… but for us it’s not required.

Thanks!

RT Training Sessions (http://bestpractical.com/services/training.html)

  • Boston March 5 & 6, 2012