[rt-users] RT3.8.7 using custom fields to restrict sending a reply on resolve

Kenneth Crocker kenn.crocker at gmail.com
Tue Feb 28 01:05:02 EST 2012


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

Kenn


On Mon, Feb 27, 2012 at 7:32 PM, Chris Herrmann <chrisherrmann7 at gmail.com>wrote:

> 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 :/
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20120227/59191dcf/attachment.htm>


More information about the rt-users mailing list