[rt-users] Need help with custom field to trigger approvals (RT 4.2)

Dion Gullotta Dion.Gullotta at faredge.com.au
Thu Oct 8 01:18:21 EDT 2015

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".



From: rt-users [mailto:rt-users-bounces at lists.bestpractical.com] On Behalf Of Dion Gullotta
Sent: Wednesday, 7 October 2015 3:53 PM
To: rt-users at lists.bestpractical.com
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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20151008/746eba85/attachment.htm>

More information about the rt-users mailing list