Wierd result

To all,

I  have created the following scrip/conditions:

Condition: User Defined
Action: Notify AdminCc's, Cc's, Requestors
Template: Reviewed (new template created as well)

Custom Condition:

# condition execution on ticket status and Custom Field value

     return ($self->TicketObj->Status eq "new" &&
             $self->Ticket->FirstCustomFieldValue('Approval-Status')
             eq "Reviewing Request");
     return 0;

Custom Action Preparation Code: none

Custom Action Cleanup code:

     # set new status for work-status

     my $cf_obj;
     my $cf_name;
     my $cf_value;

     $cf_obj = RT::CustomField->new($RT::SystemUser);
     $cf_name = "Work-Status";
     $cf_value = "Pending Decision";
     $RT::Logger->debug( $self . " cf_value = ". $cf_value . "\n" );
     $cf_obj->LoadByName( Name => $cf_name );
     $RT::Logger->debug( "Loaded \$cf_obj->Name = ". $cf_obj->Name() 
     	."\n" );
     $cf_obj->AddValueForObject( Object=>$self->TicketObj, 
  	Content=>$cf_value, );

# set new status for ticket

$RT::Logger->debug( $self->TicketObj->SetStatus("pending rv");


I have also added the new ticket status value in my RT Configuration.

My problem is 1; I get a template sent out that I did not ask for (I 

get new owner like for an owner change).
2; the ticket status doesn’t get changed.

Any ideas?  Thanks.

Kenn
LBNL

At Tuesday 5/8/2007 01:14 AM, Kenneth Crocker wrote:

To all,

    I  have created the following scrip/conditions:

    Condition: User Defined
    Action: Notify AdminCc's, Cc's, Requestors
    Template: Reviewed (new template created as well)

    Custom Condition:

    # condition execution on ticket status and Custom Field value

    return ($self->TicketObj->Status eq "new" &&
            $self->Ticket->FirstCustomFieldValue('Approval-Status')
            eq "Reviewing Request");
    return 0;

    Custom Action Preparation Code: none

    Custom Action Cleanup code:

    # set new status for work-status

    my $cf_obj;
    my $cf_name;
    my $cf_value;

    $cf_obj = RT::CustomField->new($RT::SystemUser);
    $cf_name = "Work-Status";
    $cf_value = "Pending Decision";
    $RT::Logger->debug( $self . " cf_value = ". $cf_value . "\n" );
    $cf_obj->LoadByName( Name => $cf_name );
    $RT::Logger->debug( "Loaded \$cf_obj->Name = ". 

$cf_obj->Name() .“\n” );
$cf_obj->AddValueForObject(
Object=>$self->TicketObj, Content=>$cf_value, );

    # set new status for ticket

    $RT::Logger->debug( $self->TicketObj->SetStatus("pending rv");


    I have also added the new ticket status value in my RT Configuration.

    My problem is 1; I get a template sent out that I did not 

ask for (I get new owner like for an owner change).
2; the ticket status doesn’t get changed.

    Any ideas?  Thanks.

Kenn
LBNL

Hi Kenn,

One question - what action in RT are you hoping will trigger this scrip?

Re the two problems:

  1. The unasked-for template email must be generated by a different
    scrip - there’s no way this scrip could use a template other than the
    one you specified.

  2. The custom condition code seems problematic - it doesn’t check for
    transaction type, which means it will return 1 for ANY ticket
    transaction for a ticket with status = new and custom field = your
    value. Is that what you want, or do you want to capture a CF change?

Also, by trying to change status in the scrip action, you may be
running into the problem with whatever status value was on the screen
overriding your scrip change.

Hope this is helpful,
Steve

Hi Kenn,

In addition to what Steve pointed out, I think you have an error in your
condition code. The second term of

            $self->Ticket->FirstCustomFieldValue('Approval-Status')

should probably be TicketObj instead of Ticket.

Something I started doing with my scrips to avoid making Ticket/TicketObj
mistakes when jumping between scrips and templates is I always start my
scrips off with the following 2 lines:
my $Ticket = $self->TicketObj;
my $Transaction = $self->TransactionObj;

Now I can just copy code snippets between templates and scrips without
having to change any of the Transaction or Ticket references (for instance,
ticket status is $Ticket->Status whether it’s in a scrip or
template). This is especially handy when I have subroutines that I use in
both scrips and templates. Plus I never get the $self->Ticket or
$self->$TicketObj errors anymore.

Gene

At 10:14 PM 5/7/2007, Kenneth Crocker wrote:

To all,

    I  have created the following scrip/conditions:

    Condition: User Defined
    Action: Notify AdminCc's, Cc's, Requestors
    Template: Reviewed (new template created as well)

    Custom Condition:

    # condition execution on ticket status and Custom Field value

    return ($self->TicketObj->Status eq "new" &&
            $self->Ticket->FirstCustomFieldValue('Approval-Status')
            eq "Reviewing Request");
    return 0;

    Custom Action Preparation Code: none

    Custom Action Cleanup code:

    # set new status for work-status

    my $cf_obj;
    my $cf_name;
    my $cf_value;

    $cf_obj = RT::CustomField->new($RT::SystemUser);
    $cf_name = "Work-Status";
    $cf_value = "Pending Decision";
    $RT::Logger->debug( $self . " cf_value = ". $cf_value . "\n" );
    $cf_obj->LoadByName( Name => $cf_name );
    $RT::Logger->debug( "Loaded \$cf_obj->Name = ". 

$cf_obj->Name() .“\n” );
$cf_obj->AddValueForObject(
Object=>$self->TicketObj, Content=>$cf_value, );

    # set new status for ticket

    $RT::Logger->debug( $self->TicketObj->SetStatus("pending rv");


    I have also added the new ticket status value in my RT Configuration.

    My problem is 1; I get a template sent out that I did not ask for 

(I get new owner like for an owner change).
2; the ticket status doesn’t get changed.

    Any ideas?  Thanks.

Kenn
LBNL


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

Stephan,

Thanks for answering. You're right, too confusing. I was originaling 

looking to key off a CF change. I re-thought my condition code and
decide to just key off the status change.Now I have:

return ($self->TransactionObj->Type eq “Status” &&
$self->TransactionObj->NewValue eq “pending rv”);
return 0;

and that works OK. I am still getting an extra template so I'll look at 

my other scrips.
Also, I am not getting a change to a CF in the process. The code is:

my $cf_obj;
my $cf_name;
my $cf_value;

$cf_obj = RT::CustomField->new($RT::SystemUser);
$cf_name = “Work-Status”;
$cf_value = “Pending Decision”;
$RT::Logger->debug( $self . " cf_value = ". $cf_value . “\n” );
$cf_obj->LoadByName( Name => $cf_name );
$RT::Logger->debug( “Loa
ded $cf_obj->Name = “. $cf_obj->Name() .”\n” );
$cf_obj->AddValueForObject( Object=>$self->TicketObj, Content=>$cf_value, );

Any ideas?  Thanks.

Kenn
LBNL

Stephen Turner wrote:

Gene,

You're hints were helpful, thank you. Now I am discovering that what I 

really want to do is automatically change the ticket status based on a
particular CF being change to a certain value. I’m no Perl guru. I have
read alot about TransactionBatch, so I know I have to enable that, but
I’m not sure how to approach evaluating a single CF or even how to get
it to be evaluated before sending a notification and changing the
status. Any help here would be greatly appreciated. Thanks in advance.

Kenn
LBNL

Gene LeDuc wrote:

Kenn, here’s the condition code from one of my scrips that triggers when CF
’DMCA State’ changes to ‘TNS_Restore’’. This uses TransactionCreate, not
Batch.

{ ### Testing CF triggers
my $Transaction = $self->TransactionObj;
my $Ticket = $self->TicketObj;
my $val = $Transaction->Type eq “CustomField”
&& $Transaction->Field == get_custom_id(‘DMCA State’)
&& $Transaction->NewValue eq ‘TNS Restore’;
return $val;

Returns custom field ID number from Name

usage: $id = get_custom_id($name);

sub get_custom_id {
my $target_name = $_[0];
my $cf = RT::CustomField->new($RT::SystemUser);
$cf->LoadByNameAndQueue(Name=>$target_name, Queue=>$Ticket->QueueObj);
return $cf->id if $cf;
return undef;
}
}

Then my Prep code would be something like:

Sets status to ‘rejected’

my $Ticket = $self->TicketObj;
$Ticket->SetStatus(‘rejected’);

Hope this helps you,
Gene

At 12:45 PM 5/10/2007, Kenneth Crocker wrote:

Gene,

Thanks a bunch! I'll try it in a couple days and let you know. thanks 

again for the great help.

Kenn
LBNL

Gene LeDuc wrote: