Difference between revisions of "RequireCFResolve"

From Request Tracker Wiki
Jump to navigation Jump to search
m (3 revisions imported)
 
 
Line 15: Line 15:
  ======================================================================
  ======================================================================
   
   
  Part 1:  "Modify.html/Default" callback (user submitted a form from
  Part 1:  "Modify.html/Default" callback (user submitted a form from The Basics)
          The Basics)
  <pre>
   
  <%INIT>
  <%INIT>
  # Modify.html/Default
  # Modify.html/Default
Line 44: Line 43:
  <%ARGS>
  <%ARGS>
  </%ARGS>
  </%ARGS>
</pre>
   
   
  ======================================================================
  ======================================================================
   
   
  Part 2: "Update.html/Initial" callback.  User clicked "Resolve"
  Part 2: "Update.html/Initial" callback.  User clicked "Resolve" hyperlink on a ticket (upper right).
        hyperlink on a ticket (upper right).
  <pre>
   
  <%INIT>
  <%INIT>
  my $ARGSRef = $ARGS{'ARGSRef'};
  my $ARGSRef = $ARGS{'ARGSRef'};
Line 75: Line 74:
  <%ARGS>
  <%ARGS>
  </%ARGS>
  </%ARGS>
</pre>

Latest revision as of 04:50, 29 August 2018

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>