Managed to get it working, here's my terrible code (this goes in the custom 
condition box, all others empty):

my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = "Needs Approval";
my $cf_value = "Flag";

return 0 unless $self->TicketObj->FirstCustomFieldValue('65') eq 'Yes';
$cf_obj->LoadByName( Name => $cf_name );
$ticket->AddCustomFieldValue( Field=>$cf_obj, Value=>$cf_value, 
RecordTransaction=>0 );
return 1;

This will delete the value of the Needs Approval custom field (The 'flag') from 
Yes to blank, which works well for my needs.

With this in place it triggers one approval request every time someone sets the 
"Needs Approval" dropdown box to "Yes".

Cheers,

Dion

From: rt-users [mailto:[email protected]] On Behalf Of 
Dion Gullotta
Sent: Wednesday, 7 October 2015 3:53 PM
To: [email protected]
Subject: [rt-users] Need help with custom field to trigger approvals (RT 4.2)

Hi all,

I would like to trigger an approval request with a custom field value.

We have set up approvals normally which work great,  but we wanted to be able 
to set a custom field value to trigger the creation instead.

We have a custom field called "Needs Approval" and we have a scrip with the 
custom condition:


my $Ticket = $self->TicketObj;

return 0 unless $self->TicketObj->FirstCustomFieldValue('65') eq 'Yes';
         return 1;


Prep code and Commit code are blank.  Action is "Create tickets" and Template 
"Create Approval Request" as normal.

This all works fine initially but because the "Needs Approval" field remains 
set to "Yes" then every time the ticket is touched another approval gets 
created. So I am trying to unset "Needs Approval" from "Yes" to "No" after it's 
been triggered.

I have tried this in the Commit code (prep code blank):


$cf->LoadByName( Name => 'Needs Approval' );

$self->TicketObj->AddCustomFieldValue( Field => '$cf', Value => 'No' );


But it doesn't seem to work.

Any advice or help appreciated as always.

Thank you.

Dion Gullotta
Far Edge Technology

p. 02 84251400
http://www.faredge.com.au


Reply via email to