RequireCFResolve

From Request Tracker Wiki
Jump to navigation Jump to search

The following is old, but kept for reference. You should instead look into using RT-Extension-MandatoryOnTransition (search for it, it's in CPAN).


SUMMARY:

Here's how I did it, based on code from others.  Two callbacks
that are very similar in code.  The end result is that if a
user tries to resolve a ticket when a certain CF is not set,
that user will get an error message within the RT page
due to the Abort() call.  In an ideal world, the user would
see the error message and be provided with the data to correct,
but I couldn't figure out how to get that to work properly
using the callback calls *provided by RT*.

======================================================================

Part 1:  "Modify.html/Default" callback (user submitted a form from The Basics)
 <%INIT>
 # Modify.html/Default
 
 my $ARGSRef = $ARGS{'ARGSRef'};
 # Bail if a resolve operation is not being tried.
 my $Status = $$ARGSRef{'Status'};
 if ($Status !~ ''/resolved/'') {
    return 1;
 }
 
 my $ticket = LoadTicket($$ARGSRef{'id'});
 my $CustomFields = $ticket->QueueObj->TicketCustomFields();
 while (my $CustomField = $CustomFields->Next()) {
     my $nam = $CustomField->Name;
     my $val = $ticket->FirstCustomFieldValue($nam);
 
     if (($nam =~ /SomeRequiredField/i) and ($val =~ /^\s*$/)) {
         Abort("ERROR: SomeRequiredField must be set to allow resolving.  Please use your browser's 'Back' button to correct this issue as desired.");
    }
 }
 
 return 1;
 
 </%INIT>
 <%ARGS>
 </%ARGS>
======================================================================

Part 2: "Update.html/Initial" callback.  User clicked "Resolve" hyperlink on a ticket (upper right).
 <%INIT>
 my $ARGSRef = $ARGS{'ARGSRef'};
 
 # Bail if a resolve operation is not being tried.
 my $DefaultStatus = $$ARGSRef{'DefaultStatus'};
 my $Status = $$ARGSRef{'Status'};
 if ($DefaultStatus !~ /resolved/ && $Status !~ /resolved/) {
    return 1;
 }
 
 my $ticket = LoadTicket($$ARGSRef{'id'});
 my $CustomFields = $ticket->QueueObj->TicketCustomFields();
 while (my $CustomField = $CustomFields->Next()) {
     my $nam = $CustomField->Name;
     my $val = $ticket->FirstCustomFieldValue($nam);
 
     if (($nam =~ /SomeRequiredField/i) and ($val =~ /^\s*$/)) {
         Abort("ERROR: SomeRequiredField must be set to allow resolving.  Please use your browser's 'Back' button to correct this issue as desired.");   }
 }
 
 return 1;
 
 </%INIT>
 <%ARGS>
 </%ARGS>