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

Craig Kaiser craig at bestpractical.com
Thu Jun 3 17:12:35 EDT 2021


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

- Log -----------------------------------------------------------------
commit b196bfe7f336b4568d9b41ab485f6f348abd2c7c
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..438e743c41 100644
--- a/lib/RT/Action/CreateTickets.pm
+++ b/lib/RT/Action/CreateTickets.pm
@@ -176,6 +176,24 @@ 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. For example, taking a looking at
+the example above. The template creates two different tickets, maybe a sexond approval ticket shouldn't
+be created if the tickets 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 +241,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 +338,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 +762,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