SpawnChildTicket

From Request Tracker Wiki
Jump to navigation Jump to search

Module version

This is a simple plugin solution for 3.8 that provides a new option in the Links box on the Ticket Display page that allows you to select a type of Link and the Queue where the ticket will be created. It uses RT's build in Clone link to copy data.

RT-Extension-SpawnLinkedTicketInQueue

[CallBack]s based solution

This is a trivial code snippet that's designed to be used in a Callback and will create a "spawn child ticket" button and pulldown of allowed child queues. It gets the list of allowed queues from a config variable. This lets me say that the Bugs queue can spawn children in the Bugs and Feature Requeues queues, and that the Sysadmin queue can spawn in the sysadmin queue.

%# this is kinda ugly.
 %#
 
 %# only display if there's a possible child-queue
 % if( @{$session{'spawn_in_queues'}} > 0 ) {
 
   <FORM ACTION="<% $RT::WebPath %>/Ticket/Create.html" NAME="CreateTicketInQueue">
   <input type="submit" value="Spawn child in">
   <SELECT NAME ="Queue">
 %   foreach my $queue (@{$session{'spawn_in_queues'}}) {
       <OPTION
       VALUE="<%$queue->{'id'}%>"
       <%$Default && ($queue->{'id'} == $Default) && 'SELECTED'%>>
       <%$queue->{'Name'}%>
 %     if (($Verbose) and ($queue->{'Description'}) ){
         (<%$queue->{'Description'}%>)
 %     }
       </OPTION>
 %   }
   </SELECT>
 
 %# boring values. these are no brainer copies
   <input type="hidden" name="new-MemberOf" value="<%$Ticket->Id%>">
   <input type="hidden" name="Subject" value="Child of: <%$Ticket->Subject%>">
 
 %# I'd like to pass the CustomFields along, but I don't think I can here
 %# at least not without creating a CustomField object, and patching
 %# EditCustomFields
   </FORM>
 %}
 
 <%INIT>
 # this is kinda klunky, take the things from the config
 # dump to a hash, then iterate over all queues, and find the matches
 # that gives us a nice array of hashes (and is close to SelectNewTicketQueue)
 my %allowed;
 foreach (@{$RT::CHILD_SPAWN->{lc $Ticket->QueueObj->Name} }) {
    $allowed{$_} = 1;
 }
 @{$session{'spawn_in_queues'}} = ();
 my $q=new RT::Queues($session{'CurrentUser'});
 $q->UnLimit;
 while (my $queue=$q->Next) {
     if( $allowed{lc $queue->Name} ) {
        my $ds = { Name => $queue->Name,
                   Description => $queue->Description,
                   id => $queue->id };
        push (@{$session{'spawn_in_queues'}}, $ds);
    }
 }
 </%INIT>
 
 <%ARGS>
 $Ticket => undef
 $Verbose =>  0
 $Default => 0
 </%ARGS>
 
 

my site config file has this:

# this controls which queues can spawn child tickets where.
 # it might be overkill, and might just make more sense to allow spawning
 # everywhere, but I think that'll just be confusing.
 Set($CHILD_SPAWN, {
           "sysadmin"         => ["sysadmin"],
           "bugs"             => ["bugs", "feature requests"],
           "feature requests" => ["bugs", "feature requests"],
 
           } );
 
 
 

Future

It'd be nice if in addition to prepopulating the Subject, it could prepopulate the custom fields.But I don't see that happening yet. oh well.

Errors

I tried this and got strange errors. Shold I store the code in BeforeUpdate Callback? I get:
error:   	Can't call method "Id" on an undefined value at      /usr/local/share/request-tracker3.4/html/Callbacks/SpawnChildTicket/Ticket/Display.html/BeforeDisplay line 23.
19:   	% }
20:  	</SELECT>
21:
22:  	%# boring values. these are no brainer copies
23:  	<input type="hidden" name="new-MemberOf" value="<%$Ticket->Id%>">
24:  	<input type="hidden" name="Subject" value="Child of: <%$Ticket->Subject%>">
25:
26:  	%# I'd like to pass the CustomFields along, but I don't think I can here
27:  	%# at least not without creating a CustomField object, and patching