[rt-users] Disallow 'resolve' unless a CF is set?

Jeff Blaine jblaine at kickflop.net
Tue Jan 11 12:39:28 EST 2011


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'};
if ($DefaultStatus !~ /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>



More information about the rt-users mailing list