[rt-users] Custom Condition To Send Email on Resolve if No Article Sent as Part of Resolve

Alex Peters alex at peters.net
Sat Aug 2 22:28:26 EDT 2014


If I understand correctly, you only want the scrip to apply if there's
correspondence, AND the status is changed to resolved, AND a RefersTo link
is added.

Each of these actions on the ticket occurs as a separate transaction, and
the order in which those transactions occur is not clearly defined.
 Therefore, your suspicion is correct that running the scrip in transaction
batch mode is required.

When run in batch mode, you can access a list of all of the transactions
this way:

my @txns = @{ $self->TicketObj->TransactionBatch };

You can then loop over each transaction looking for the required traits.
 This untested code should be close to what you need:

my ($found_correspondence, $found_resolved, $found_refersto);
my @txns = @{ $self->TicketObj->TransactionBatch };
for my $txn (@txns) {

    # look for correspondence
    if ($txn->Type eq 'Correspond') {
        RT::Logger->debug('this operation involves correspondence');
        $found_correspondence++;
        next;
    }

    # look for status change to resolved
    if (
        (
            $txn->Type eq 'Status'
            or ($txn->Type eq 'Set' and $txn->Field eq 'Status')
        )
        and $txn->NewValue eq 'resolved'
    ) {
        RT::Logger->debug('this operation involves resolution');
        $found_resolved++;
        next;
    }

    # look for addition of RefersTo link
    if ($txn->Type eq 'AddLink' and $txn->Field eq 'RefersTo') {
        RT::Logger->debug('this operation involves adding a RefersTo link');
        $found_refersto++;
        next;
    }

}

return 0 if not $found_correspondence;
return 0 if not $found_resolved;
return 0 if not $found_refersto;
return 1;


On 03/08/2014 10:51 am, "Foggi, Nicola" <NFOGGI at depaul.edu> wrote:

> Version : RT-4.0.19
>
> Hey All,
>
> Running into a slight problem with a new queue I'm attempting to roll out
> a new queue that uses some "pre-canned" template responses using Articles
> from the integrated RTFM system in 4.0.19 now.  I've changed the lifecycle
> to make the open -> resolve a default RESPOND vs COMMENT and that's
> working.  However, I want to send a default template response if the admin
> forgets to choose an article to respond with.  I came up with the following
> code below for the custom codition.  I'm detecting if the ticket has a
> ReferTo set and then if it doesn't return code 1 to that the scrip executes
> which sends the template, otherwise, sets it to 0 so it skips the scrip.
>
> The problem I'm running into is it appears the run the scrip prior to
> linking the article to ticket, so it always thinks the admin hasn't
> attached an article when they actually have.  Is there anything I can do to
> execute the scrip post process of attaching the article (I tried setting it
> to Transaction Batch).
>
> Any ideas would be greatly appreciated.
>
> Thanks
>
> Nicola
>
> [custom condition below]
>
> my $RefersToTickets = $self->TicketObj->RefersTo;
> my $FirstRefersToTicketLink = $RefersToTickets->Next;
>
> my $returncode = 0;
>
> my $txn = $self->TransactionObj;#
> my $type = $txn->Type;
> return 0 unless $type eq "Status"
>     || ( $type eq 'Set' && $txn->Field eq 'Status');
>
> if ($txn->NewValue eq "resolved") {
>
>    eval {$FirstRefersToTicketLink->TargetURI->URI};
>    my $results = $@;
>    $RT::Logger->info('219 - ' . $results);
>    if ($results =~ qr{^Can't call method}) {
>       $RT::Logger->info('UNDEFINED');
>       $returncode = 1;
>    } else {
>       $returncode = 0;
>    };
>
> };
>
> $RT::Logger->info('Return Code: ' . $returncode);
> return $returncode;
> --
> RT Training - Boston, September 9-10
> http://bestpractical.com/training
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20140803/e82d2fc5/attachment.htm>


More information about the rt-users mailing list