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.