[rt-users] Have a programatically set Custom Field trigger a Condition

suIIy bglasson at bytecraft.com.au
Tue Jul 19 02:56:04 EDT 2011


Hi All

I'm working on implementing a workflow based queue in RT3.6 based on the
instructions here;

http://requesttracker.wikia.com/wiki/WorkFlow

How it works is this.

A master ticket is created with 3 custom fields. Each custom field can have
2 values "Required" and "Completed"

When "Required" is set, a scrip creates a child ticket.

When the child ticket is closed, a scrip updates the master ticket and
changes the Custom Field in that ticket from "Required" to "Complete"

Every thing works fine at this point.

I then decided that it would be a neat idea if when the child task is
completed, the next child task could automatically begin.

In theory, to do this would simply require that the "On Resolve" scrip
update the next Custom Field in the workflow, setting it to "Required" which
should trigger the next child ticket.  

After adding a few extra lines to the On Resolve scrip I am now
automatically updating the Custom Field in the next step to "Required",
which should trigger a condition.

This is where I'm stalled.

It seems that the Condition is not triggered when you programmatically set
the Custom Field to "Required". If you unset it and then set it back to
"Required" manually it works just fine.

This is the code for the Condition as per the Workflow wiki page;

8<------------------------------------------------------------------------------------
# Local condition to check that a custom field
# has been set to "Required".
# -Chuck Boeheim 3/13/06

package RT::Condition::FieldRequired;
require RT::Condition::Generic;

use strict;
use vars qw/@ISA/;
@ISA = qw(RT::Condition::Generic);


=head2 IsApplicable
 
If the field named as an argument becomes 'Required'.
Only triggers on transitions, not if it already had
that value.
 
=cut
 
sub IsApplicable {
    my $self = shift;
    my $field = $self->Argument;
    my $trans = $self->TransactionObj;
   
    if ($trans->Type eq 'Create')
    {
       return 1 if $trans->TicketObj->FirstCustomFieldValue($field) =~
/^Required/;
    }
   
    if ($trans->Type eq 'CustomField')
    {
       my $cf = RT::CustomField->new($self->CurrentUser);
       $cf->Load($field);
       return 1 if $trans->Field == $cf->Id && $trans->NewValue =~
/^Required/;
    }
   
    return undef;
}
 
1;

8<------------------------------------------------------------------------------------

I reckon the trouble is in this particular script, but I don't really know
perl at all so I could be wrong. I am assuming that I might need another
<code> if ($trans->Type eq '???)  </code> block maybe?
 
If anybody has any ideas on what I need to do to make a programatically set
custom field trigger a condition I would sure appreciate it.

I don't want to load up this post with tonnes of code so if there is any
extra info you require please let me know.

Thanks in advance.
-- 
View this message in context: http://old.nabble.com/Have-a-programatically-set-Custom-Field-trigger-a-Condition-tp32088731p32088731.html
Sent from the Request Tracker - User mailing list archive at Nabble.com.




More information about the rt-users mailing list