Scrip for adding to the custom field based on another CF

I have a scrip currently that checks for status change from X–> Y and if
true, adds an entry to the Custom Field “RMA Num”. It adds our RMA number,
which is really just “RMA-$RT_Ticket_Number”

They have asked me to change the number based on another CF “RMA TYPE”. If
the RMA type = “Student Withdrawl” they want the RMA number to be appended
with “WD”

My perl skills are limited to copy/paste and tweaking existing… so I
would like a little bit of help with my If/Then statement. The idea being:

IF CustomField{RMA Type} = Student Withdrawl
THEN $Append = "-WD"
ELSE $Append = “”

Then in the current line (below)
my $Value = “RMA-” . $Num ;

would be changed to
my $Value = “RMA-” . $Num . $Append ;

Custom action preparation code:

Define the Custom Field to Act on

my $CFName = “RMA Num”;

#Get the RT Ticket Number
my $Num = $self->TicketObj->id();

Define the desired value for the CF

my $Value = “RMA-” . $Num ;

$self->TicketObj->AddCustomFieldValue( Field => $CFName, Value => $Value );

return 1;

http://www.wikiak.org

Associate yourself with men of good quality if you esteem
your own reputation; for 'tis better to be alone then in bad
company. - George Washington, Rules of Civility

I have a scrip currently that checks for status change from X–> Y and if true, adds an entry to the Custom Field “RMA Num”. It adds our RMA number, which is really just “RMA-$RT_Ticket_Number”

They have asked me to change the number based on another CF “RMA TYPE”. If the RMA type = “Student Withdrawl” they want the RMA number to be appended with “WD”

My perl skills are limited to copy/paste and tweaking existing… so I would like a little bit of help with my If/Then statement. The idea being:

IF CustomField{RMA Type} = Student Withdrawl
THEN $Append = "-WD"
ELSE $Append = “”

Then in the current line (below)
my $Value = “RMA-” . $Num ;

would be changed to
my $Value = “RMA-” . $Num . $Append ;

This can be done with one ternary operator:
my $value = $self->TicketObj->FirstCustomFieldValue(‘RMA Type’) eq ‘Student Withdrawl’ ? “RMA-” . $Num : “RMA-” . $Num . $Append;

Some notes:

  • The condition here is: $self->TicketObj->FirstCustomFieldValue(‘RMA Type’) eq ‘Student Withdrawl’
  • If the condition is true then $value will equal what’s between the ? and the : (colon)
  • If the condition is false then $value will equal what’s between the : and the ; (semi-colon)

Landon Stewart : lstewart@iweb.com
Lead Specialist, Abuse and Security Management
Spécialiste principal, gestion des abus et sécurité
http://iweb.com : +1 (888) 909-4932

signature.asc (203 Bytes)

You should move your scrip code from the Prepare box to the Commit box.
Making changes to tickets in the Prepare stage of a transaction can cause
unintended side effects and is not recommended.On Thu, 22 Jan 2015 2:07 am Kevin Squire gentgeen@wikiak.org wrote:

I have a scrip currently that checks for status change from X–> Y and if
true, adds an entry to the Custom Field “RMA Num”. It adds our RMA number,
which is really just “RMA-$RT_Ticket_Number”

They have asked me to change the number based on another CF “RMA TYPE”.
If the RMA type = “Student Withdrawl” they want the RMA number to be
appended with “WD”

My perl skills are limited to copy/paste and tweaking existing… so I
would like a little bit of help with my If/Then statement. The idea being:

IF CustomField{RMA Type} = Student Withdrawl
THEN $Append = "-WD"
ELSE $Append = “”

Then in the current line (below)
my $Value = “RMA-” . $Num ;

would be changed to
my $Value = “RMA-” . $Num . $Append ;

Custom action preparation code:

Define the Custom Field to Act on

my $CFName = “RMA Num”;

#Get the RT Ticket Number
my $Num = $self->TicketObj->id();

Define the desired value for the CF

my $Value = “RMA-” . $Num ;

$self->TicketObj->AddCustomFieldValue( Field => $CFName, Value => $Value );

return 1;


http://www.wikiak.org

#############################################################
Associate yourself with men of good quality if you esteem
your own reputation; for 'tis better to be alone then in bad
company. - George Washington, Rules of Civility

I was not aware of this.

When you say “Commit box”, are you referring to the “Custom action
cleanup code” box?On Wed, 21 Jan 2015 21:35:47 +0000 Alex Peters alex@peters.net wrote:

You should move your scrip code from the Prepare box to the Commit
box. Making changes to tickets in the Prepare stage of a transaction
can cause unintended side effects and is not recommended.

http://www.wikiak.org

Associate yourself with men of good quality if you esteem
your own reputation; for 'tis better to be alone then in bad
company. - George Washington, Rules of Civility

Sorry, yes, that one.

There are some “preview” operations that run the prepare code on the
assumption that nothing will change. In such circumstances, your custom
field would be set even before someone hits the “Update” button. It’s
always best not to have the Prepare code make any changes.

The “cleanup” box should probably be renamed, since everywhere else it
seems to be known as “commit.” The distinction would be clearer.

The commit code won’t run unless the prepare code returns a true value, so
in that box you could write “1;” to ensure that the commit code always runs.On Thu, 22 Jan 2015 9:16 am Kevin Squire gentgeen@wikiak.org wrote:

I was not aware of this.

When you say “Commit box”, are you referring to the “Custom action
cleanup code” box?

On Wed, 21 Jan 2015 21:35:47 +0000 Alex Peters alex@peters.net wrote:

You should move your scrip code from the Prepare box to the Commit
box. Making changes to tickets in the Prepare stage of a transaction
can cause unintended side effects and is not recommended.


http://www.wikiak.org

#############################################################
Associate yourself with men of good quality if you esteem
your own reputation; for 'tis better to be alone then in bad
company. - George Washington, Rules of Civility

Such an elegant solution - thank you.