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

Stuart Browne stuart.browne at ausregistry.com.au
Tue Jan 11 17:24:20 EST 2011


I don't suppose you could throw that up onto the wiki so people don't have to hunt it down through the mailing list archives? :)

*copies locally to implement later*

> -----Original Message-----
> From: rt-users-bounces at lists.bestpractical.com [mailto:rt-users-
> bounces at lists.bestpractical.com] On Behalf Of Jeff Blaine
> Sent: Wednesday, 12 January 2011 4:39 AM
> To: rt-users at lists.bestpractical.com
> Subject: Re: [rt-users] Disallow 'resolve' unless a CF is set?
> 
> 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