Scrip to Change Queues based on Department

Hello,

I am trying to write a new Scrip that will look at the custom field “Department” where the field = Pink and move tickets from our ‘User_Maintenance’ queue to our ‘Pink - User Access’ queue.

I am running RT version 4.4.4

What I have right now is:
Condition - On Create
Action - User Defined
Template - Blank

Custom condition:

my $txn = $self->TransactionObj;
if ($txn->Type eq ‘CustomField’) {
my $cf = RT::CustomField->new( $self->CurrentUser );
$cf->Load( $txn->Field );
return 0 unless $cf->Name eq ‘Department’;
return 0 unless $txn->NewValue eq “Pink”;
return 1;
}
else {
return 0;
}
return 0;

Custom action preparation code:

return 1;

Custom action commit code:

my $TargetQueueName = 'User_Maintenance’;
my $NewStatus = ‘Pink - User Access’;

if (($self->TicketObj->Status eq “$NewStatus”’) &&
($self->TicketObj->QueueObj->Name ne “$TargetQueueName”)) {
my $TicketObj = $self->TicketObj;
my $Id = $TicketObj->Id;
my $Status = $TicketObj->Status;
my $QueueName = $TicketObj->QueueObj->Name;

if ($Status ne $NewStatus) {
my ($tstatus, $tmsg) = $TicketObj->SetStatus("$NewStatus");
$RT::Logger->info(Changing status of ticket #’. $Id ." to “. $NewStatus);
unless ($tstatus) {
die “Error: $tmsg”;
}
}
if ($QueueName ne $TargetQueueName) {
my ($qstatus, $qmsg) = $TicketObj->SetQueue($TargetQueueName”);
$RT::Logger->info(“Moving Ticket #”. $Id ." to “. $TargetQueueName .”
Queue.");
unless ($qstatus) {
die “Error: $qmsg”;
}
}
}

When I click on Save Changes, I get an error that says:
Modify scrip #36 .cke{visibility:hidden;}

  • Scrip 36: CustomCommitCode updated
  • Couldn’t compile CustomCommitCode codeblock 'my $TargetQueueName = 'User_Maintenance’; my $NewStatus = ‘€˜Pink- User Access’€™; if (($self->TicketObj->Status eq "€œ$NewStatus"€’) && ($self->TicketObj->QueueObj->Name ne “€œ$TargetQueueName"€)) { my $TicketObj = $self->TicketObj; my $Id = $TicketObj->Id; my $Status = $TicketObj->Status; my $QueueName = $TicketObj->QueueObj->Name; if ($Status ne $NewStatus) { my ($tstatus, $tmsg) = $TicketObj->SetStatus(”$NewStatus"); $RT::Logger->info(“Changing status of ticket #‘€. $Id ." to "€œ. $NewStatus); unless ($tstatus) { die “€œError: $tmsg"€; } } if ($QueueName ne $TargetQueueName) { my ($qstatus, $qmsg) = $TicketObj->SetQueue(”$TargetQueueName”); $RT::Logger->info("Moving Ticket #“€. $Id .” to ". $TargetQueueName ."€œ Queue."€); unless ($qstatus) { die "€œError: $qmsg"€; } } } return 1;’: Unrecognized character \xC2 in column 48 at (eval 1635) line 1. Stack: [(eval 1635):1] [/opt/rt4/share/html/Admin/Scrips/Modify.html:139] [/opt/rt4/share/html/Admin/autohandler:49] [/opt/rt4/sbin/…/lib/RT/Interface/Web.pm:697] [/opt/rt4/sbin/…/lib/RT/Interface/Web.pm:376] [/opt/rt4/share/html/autohandler:53]

And then my code is updated weirdly, now showing the below in the Custom action commit code:

my $TargetQueueName = 'User_Maintenance’;
my $NewStatus = '€˜Pink - User Access’€™;

if (($self->TicketObj->Status eq "€œ$NewStatus"€’) &&
($self->TicketObj->QueueObj->Name ne "€œ$TargetQueueName"€)) {
my $TicketObj = $self->TicketObj;
my $Id = $TicketObj->Id;
my $Status = $TicketObj->Status;
my $QueueName = $TicketObj->QueueObj->Name;

if ($Status ne $NewStatus) {
my ($tstatus, $tmsg) = $TicketObj->SetStatus("$NewStatus");
$RT::Logger->info(“Changing status of ticket #'€. $Id ." to "€œ. $NewStatus);
unless ($tstatus) {
die “€œError: $tmsg"€;
}
}
if ($QueueName ne $TargetQueueName) {
my ($qstatus, $qmsg) = $TicketObj->SetQueue(”$TargetQueueName”);
$RT::Logger->info("Moving Ticket #“€. $Id .” to ". $TargetQueueName ."€œ
Queue."€);
unless ($qstatus) {
die "€œError: $qmsg"€;
}
}
}
return 1;

Any advise? - Please note that I am new to writing scrips so I have compiled what I have above from other scrips we have. We currently don’t have anything moving tickets between queues.

Your quotes are smart quotes, maybe copy and pasted from somewhere. Try replacing the " and ' in your scrip by manually typing them

I copied chunks of it from our RT scrips and then compiled it up in NotePad++. From there I am copy/pasting it into the RT window for my new scrip.

I just went through and manually changed all of the special characters and the code itself isn’t being changed anymore, but I am still getting an error:

Modify scrip #36 .cke{visibility:hidden;}

  • Couldn’t compile CustomCommitCode codeblock ‘my $TargetQueueName = ‘User_Maintenance’; my $NewStatus = ‘Pink - User Access’; if (($self->TicketObj->Status eq “$NewStatus”’) && ($self->TicketObj->QueueObj->Name ne “$TargetQueueName”)){ my $TicketObj = $self->TicketObj; my $Id = $TicketObj->Id; my $Status = $TicketObj->Status; my $QueueName = $TicketObj->QueueObj->Name; if ($Status ne $NewStatus) { my ($tstatus, $tmsg) = $TicketObj->SetStatus("$NewStatus"); $RT::Logger->info(Changing status of ticket #’. $Id ." to “. $NewStatus); unless ($tstatus) { die “Error: $tmsg”; } } if ($QueueName ne $TargetQueueName) { my ($qstatus, $qmsg) = $TicketObj->SetQueue ($TargetQueueName”); $RT::Logger->info(“Moving Ticket #’. $Id .” to “. $TargetQueueName .” Queue."); unless ($qstatus) { die “Error: $qmsg”; } } } return 1;’: Modification of a read-only value attempted at /usr/local/share/perl5/Log/Dispatch/Output.pm line 39. Stack: [/usr/local/share/perl5/Log/Dispatch/Output.pm:39] [/usr/local/share/perl5/Log/Dispatch.pm:214] [/usr/local/share/perl5/Log/Dispatch.pm:167] [/usr/local/share/perl5/Log/Dispatch.pm:145] [(eval 1716):20] [/opt/rt4/share/html/Admin/Scrips/Modify.html:139] [/opt/rt4/share/html/Admin/autohandler:49] [/opt/rt4/sbin/…/lib/RT/Interface/Web.pm:697] [/opt/rt4/sbin/…/lib/RT/Interface/Web.pm:376] [/opt/rt4/share/html/autohandler:53]

Looks like “Modification of a read-only value attempted at /usr/local/share/perl5/Log/Dispatch/Output.pm line 39” is maybe the issue now?

It is hard to read without code formatting on the pasted block, but I would just run through every line and make sure quoting and that looks right, a quick look I see $RT::Logger->info(Changing status of ticket #’. $Id ." to “. $NewStatus) which will not work since you need to quote the string portions.

RT::Logger->info("Changing status of ticket #’ $Id to $NewStatus")

Okay I will start combing through it a little more. Thanks for the help!