[Rt-commit] rt branch, 5.0/create-tickets-skip-flag, created. rt-5.0.1-427-gf9e7a76780

Craig Kaiser craig at bestpractical.com
Fri Jun 18 11:22:55 EDT 2021


The branch, 5.0/create-tickets-skip-flag has been created
        at  f9e7a767800f43facb823552f4aa7be06a554c1a (commit)

- Log -----------------------------------------------------------------
commit f9e7a767800f43facb823552f4aa7be06a554c1a
Author: craig kaiser <craig at bestpractical.com>
Date:   Wed Jun 2 09:36:40 2021 -0400

    Allow skipping of create ticket blocks through passing arg
    
    This allows for logic to be placed inside of the '===' create ticket
    blocks to decide if a ticket should be created or not.

diff --git a/lib/RT/Action/CreateTickets.pm b/lib/RT/Action/CreateTickets.pm
index af3d9d0779..d54ae56abe 100644
--- a/lib/RT/Action/CreateTickets.pm
+++ b/lib/RT/Action/CreateTickets.pm
@@ -176,6 +176,26 @@ template section after the block, you must scope it with C<our> rather
 than C<my>. Just as with other RT templates, you can also include
 Perl code in the template sections using C<{}>.
 
+=head3 SkipCreate
+
+This flag allows for ticket creation to be skipped programatically.
+Taking a look at the example above the template creates two different
+tickets, maybe a second approval ticket shouldn't be created if the
+ticket's priority is low. Using Perl logic we can check some information
+about the ticket and decide using this flag if we should skip creating
+this ticket:
+
+ ===Create-Ticket: two
+ SkipCreate: {$Tickets{'TOP'}->Priority eq 'Low' ? 1 : 0}
+ Subject: Manager approval
+ Type: approval
+ Depended-On-By: TOP
+ Refers-To: {$Tickets{"create-approval"}->Id}
+ Queue: ___Approvals
+ Content-Type: text/plain
+ Content: Your approval is requred for this ticket, too.
+ ENDOFCONTENT
+
 =head2 Acceptable Fields
 
 A complete list of acceptable fields:
@@ -223,6 +243,8 @@ A complete list of acceptable fields:
        CF-name           => custom field value
        CustomField-name  => custom field value
 
+       SkipCreate        => 0/1, if true, skip this create ticket block
+
 Fields marked with an C<*> are required.
 
 Fields marked with a C<+> may have multiple values, simply
@@ -318,8 +340,17 @@ sub CreateByTemplate {
         $T::ID    = $template_id;
         @T::AllID = @{ $self->{'create_tickets'} };
 
+        my (@links_local, @postponed_local);
         ( $T::Tickets{$template_id}, $ticketargs )
-            = $self->ParseLines( $template_id, \@links, \@postponed );
+            = $self->ParseLines( $template_id, \@links_local, \@postponed_local );
+
+
+        if ( $ticketargs->{'SkipCreate'} ) {
+            RT::Logger->debug( "Skip flag found for template $template_id, skipping" );
+            next;
+        }
+        push @links, @links_local;
+        push @postponed, @postponed_local;
 
         # Now we have a %args to work with.
         # Make sure we have at least the minimum set of
@@ -733,6 +764,7 @@ sub ParseLines {
         FinalPriority   => $args{'finalpriority'} || 0,
         SquelchMailTo   => $args{'squelchmailto'},
         Type            => $args{'type'},
+        SkipCreate      => $args{'skipcreate'} || 0,
     );
 
     if ( $args{content} ) {

-----------------------------------------------------------------------


More information about the rt-commit mailing list