Custom Condition To Send Email on Resolve if No Article Sent as Part of Resolve

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;

I’m thinking this comment in Ticket.pm might be related to what I’m seeing:

# Deal with setting up links

# TODO: Adding link may fire scrips on other end and those scrips
# could create transactions on this ticket before 'Create' transaction.
# We should implement different lifecycle: record 'Create' transaction,
# create links and only then fire create transaction's scrips.
# Ideal variant: add all links without firing scrips, record create
# transaction and only then fire scrips on the other ends of links.
# //RUZ

Looks like that comment still exists in the 4.2 code? Any ideas on a workaround if this is indeed what I’m running into?

NicolaFrom: Foggi, Nicola
Sent: Saturday, August 02, 2014 7:45 PM
To: rt-users@lists.bestpractical.com
Subject: Custom Condition To Send Email on Resolve if No Article Sent as Part of Resolve

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;

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@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
Training — Best Practical Solutions

This comment seems to refer to a ticket when it’s being created, rather
than when correspondence is being added to it later. I don’t think it’s
relevant in your case.On 3 August 2014 11:33, Foggi, Nicola NFOGGI@depaul.edu wrote:

I’m thinking this comment in Ticket.pm might be related to what I’m seeing:

# Deal with setting up links

# TODO: Adding link may fire scrips on other end and those scrips
# could create transactions on this ticket before 'Create' transaction.
#
# We should implement different lifecycle: record 'Create' transaction,
# create links and only then fire create transaction's scrips.
#
# Ideal variant: add all links without firing scrips, record create
# transaction and only then fire scrips on the other ends of links.
#
# //RUZ

Looks like that comment still exists in the 4.2 code? Any ideas on a
workaround if this is indeed what I’m running into?

Nicola


From: Foggi, Nicola
Sent: Saturday, August 02, 2014 7:45 PM
To: rt-users@lists.bestpractical.com
Subject: Custom Condition To Send Email on Resolve if No Article Sent as
Part of Resolve

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
Training — Best Practical Solutions

Thanks Alex,

That code with some modification worked for me, I only want the scip to
apply IF Status changed -> resolved AND NOT if RefersTo link is added (I
can ignore the correspondence I think safely as the significant event is
the addlink to the article (that it’s set already to send out via a
lifecycle setting) I guess feasibly the user could change it to be a
comment vs correspondence, so I’ll have to think about that. I modified
your code to the follow for the list if anyone else needs it (just a
slight change on the logic of the return codes. I didn’t kill the
correspondence yet incase I end up using it.

Thanks for your help!

Nicola

[final code used for now]

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;
}

}

if ($found_resolved) {

 return 1 if not ($found_correspondence && $found_refersto);
 return 0;

}

return 0;