Forcing Status Changes

Hello list,

I am trying to set RT to work allowing or denying certain custom statuses.
For example, I have the “X” custom status and whenever a ticket has this
status, the next status can only be “Y” or “Z”, but it cannot be “A”.

I read the foruns and I’m still not sure if it can be done by crating
scrips or by modifying Ticket_Overlay.pm (or any other file).

Actually, I’ve started creating scripconditions that check the current
status, but now I have to create the scripactions that compare the next
status with the active status, and then it will take some action: if it
isn’t a possible status change, then go back and warn. If it is a
possible status change, go ahead and change.

Has anyone tried to do this? Is there any other easier way? Is there
something done, like forcing the status changes?

Thanks a lot!
Any suggestions are welcome!

Mario Gomide

Hi Mario,

What you want to do can be done in RT with an OnStatusChange scrip that
checks $self->TransactionObj->OldValue and
$self->TransactionObj->NewValue. If the values don’t meet your criteria,
change the status back to the OldValue. I’ve never used custom status
values, so if they require unusual handling then this might not work. If
they work like standard status values, something like this should do the trick:

Condition: User Defined
Action: User Defined
Template: Global blank

Custom condition:
{ ### true if transaction is a status change
my $Transaction = $self->TransactionObj;
my $val = $Transaction->Type eq “Status”;
return $val;
}

Custom prep action:
return 1;

Custom commit action:

Check to make sure new status value makes sense

my $Transaction = $self->TransactionObj;
my $Ticket = $self->TicketObj;
my $Old = $Transaction->OldValue;
my $New = $Transaction->NewValue;
if ($Old eq “X” && ! ($New eq “Y” || $New eq “Z”)) {
$Ticket->_Set(Field=>“Status”, Value=>$Old, RecordTransaction=>0);
}
return 1;

I just typed this in without confirming that it works as-is, so there might
be something off in the syntax, but here’s what it’s doing:

  1. Fire the scrip if there’s been a status change
  2. See if the old value was “X” and the new value is not “Y” or “Z”. If so…
  3. Set the status back to the old value without creating a transaction (so
    scrips don’t fire again)

Since you have a specific list of allowed changes (“Y” and “Z”) you don’t
have to concern yourself with “A”.

Regards,
Gene

At 09:56 AM 7/6/2007, Mario Gomide wrote:

Hello list,

I am trying to set RT to work allowing or denying certain custom statuses.
For example, I have the “X” custom status and whenever a ticket has this
status, the next status can only be “Y” or “Z”, but it cannot be “A”.

I read the foruns and I’m still not sure if it can be done by crating
scrips or by modifying Ticket_Overlay.pm (or any other file).

Actually, I’ve started creating scripconditions that check the current
status, but now I have to create the scripactions that compare the next
status with the active status, and then it will take some action: if it
isn’t a possible status change, then go back and warn. If it is a possible
status change, go ahead and change.

Has anyone tried to do this? Is there any other easier way? Is there
something done, like forcing the status changes?

Thanks a lot!
Any suggestions are welcome!

Mario Gomide


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media. Buy a
copy at http://rtbook.bestpractical.com

Gene LeDuc, GSEC
Security Analyst
San Diego State University

Hi Gene, hi list,

I’ve tried out what you said, but nothing different is happening. I can
understand the logic and what the scrip does, so I tried some changes on
the custom commit action, but with no results.
How could I debug this scrip? I could start trying to do some other
changes and writing new scrips, but for any change, I don’t actually see
any results at all. Maybe i’m forgetting something, like "activating"
the scrip or something like that.

Any ideas or anywhere to look up?
Thanks again!

Mario Gomide

Gene LeDuc escreveu:

Hi Mario,

First of all, keep in mind that I’ve never used custom status codes, so if
they are set differently than the standard status codes then my code
probably won’t do what you want.

The first thing you should do is set your logging to debug (in the RT
config file). Then stick logging statements wherever you think you might
want to know what is happening and watch what gets reported in your rt.log.

I’d start with these:

Put a command like this in the custom condition code right before the
“return $val;” statement:
$RT::Logger->debug("Custom condition is " . ($val ? “True” : “False”));

And then this in the commit code right before your if statement:
$RT::Logger->debug(“Action code: Transaction OldValue is ($Old), NewValue
is ($New)”);

And then this in the block where you change the status, right after the if
statement:
$RT::Logger->debug(“Action code, changing status to ($Old)”);

Take a look at the rt.log file and see what is going on.

Good luck!
Gene

At 06:55 AM 7/17/2007, Mario Gomide wrote:

Hi Gene, hi list,

I’ve tried out what you said, but nothing different is happening. I can
understand the logic and what the scrip does, so I tried some changes on
the custom commit action, but with no results.
How could I debug this scrip? I could start trying to do some other
changes and writing new scrips, but for any change, I don’t actually see
any results at all. Maybe i’m forgetting something, like “activating” the
scrip or something like that.

Any ideas or anywhere to look up?
Thanks again!

Mario Gomide

Gene LeDuc escreveu:

Hi Mario,

What you want to do can be done in RT with an OnStatusChange scrip that
checks $self->TransactionObj->OldValue and
$self->TransactionObj->NewValue. If the values don’t meet your criteria,
change the status back to the OldValue. I’ve never used custom status
values, so if they require unusual handling then this might not work. If
they work like standard status values, something like this should do the trick:

Condition: User Defined
Action: User Defined
Template: Global blank

Custom condition:
{ ### true if transaction is a status change
my $Transaction = $self->TransactionObj;
my $val = $Transaction->Type eq “Status”;
return $val;
}

Custom prep action:
return 1;

Custom commit action:

Check to make sure new status value makes sense

my $Transaction = $self->TransactionObj;
my $Ticket = $self->TicketObj;
my $Old = $Transaction->OldValue;
my $New = $Transaction->NewValue;
if ($Old eq “X” && ! ($New eq “Y” || $New eq “Z”)) {
$Ticket->_Set(Field=>“Status”, Value=>$Old, RecordTransaction=>0);
}
return 1;

I just typed this in without confirming that it works as-is, so there
might be something off in the syntax, but here’s what it’s doing:

  1. Fire the scrip if there’s been a status change
  2. See if the old value was “X” and the new value is not “Y” or “Z”.
    If so…
  3. Set the status back to the old value without creating a transaction
    (so scrips don’t fire again)

Since you have a specific list of allowed changes (“Y” and “Z”) you don’t
have to concern yourself with “A”.

Regards,
Gene

At 09:56 AM 7/6/2007, Mario Gomide wrote:

Hello list,

I am trying to set RT to work allowing or denying certain custom statuses.
For example, I have the “X” custom status and whenever a ticket has this
status, the next status can only be “Y” or “Z”, but it cannot be “A”.

I read the foruns and I’m still not sure if it can be done by crating
scrips or by modifying Ticket_Overlay.pm (or any other file).

Actually, I’ve started creating scripconditions that check the current
status, but now I have to create the scripactions that compare the next
status with the active status, and then it will take some action: if it
isn’t a possible status change, then go back and warn. If it is a
possible status change, go ahead and change.

Has anyone tried to do this? Is there any other easier way? Is there
something done, like forcing the status changes?

Thanks a lot!
Any suggestions are welcome!

Mario Gomide


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media. Buy
a copy at http://rtbook.bestpractical.com


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media. Buy a
copy at http://rtbook.bestpractical.com

Gene LeDuc, GSEC
Security Analyst
San Diego State University

Mario,

Gene is right (he helped me a bunch when I created several scrips that 

change ticket status for a workflow design)). The entries to your log
will help a great deal. I had several scrips that made several changes
(one at a time) and when it ran into an error, the status did not get
changed. I’d take a look at your log and see what is happening. That
will help in debugging your code.

Kenn
LBNL

Gene LeDuc wrote:

Hi Kenn, hi Gene!

I had some trouble with the logging part, but I fixed it. Then I had
this problem:
[error]: Scrip Prepare XX died. - Undefined subroutine
&Scalar::Util::weaken called at /usr/local/rt3/lib/RT/Action/Generic.pm
line 107.

This was also fixed after updating Scalar::Util via CPAN with the command:
#cpan -fi Scalar::Util
but still got nothing… so I rebooted and it began to work, and now my
scrip is running and logging.

Apparently, the scrip is working fine, and now back to my original
problem: When a ticket with status “A” cannot change to status “B”, the
result text shows that this status change occurred (Status changed from
A to B), even though it in fact didn’t ocurr (the status is unchanged).
How can I, in this case, show an error message like “ERROR: Status
cannot be changed from A to B! Status remains A.” on the results part
after modifying a ticket?
I’ve tried to set in the scrip, inside the “if” statement:
return $self->loc(“TEXT TELLING THE USER HE CANT CHANGE FROM STATUS A TO
B”);
but my text doesn’t appear… since I’m sort of new to perl and
customizing RT, this was like a blind guess…

Any ideas?
Anyway, thanks so much for your help so far!

Mario

Kenneth Crocker escreveu:

Hey everyone!

I’m still trying to solve this problem.
The scrip is working fine: Only the pre-defined changes of status are
accepted. Other pre-defined status changes are denied

The problem is that whenever a denied change occurs, the result message
is: Status changed from A to B.

I’ve tried to do some modifications to Transaction_Overlay.pm in the
part bellow, but with no success.

elsif ( $type =~ /Status/ ) {
    if ( $self->Field eq 'Status' ) {
        if ( $self->NewValue eq 'deleted' ) {
            return ( $self->loc( "[_1] deleted", $obj_type ) );
        }
        else {
            return (
                $self->loc(
                    "Status changed from [_1] to [_2]",
                    "'" . $self->loc( $self->OldValue ) . "'",
                    "'" . $self->loc( $self->NewValue ) . "'"
                )
            );

        }
    }

So, what should I do?

Thanks to all.
Mario Gomide

Mario Gomide wrote: