Getting a custom field value and setting the priority

I have a custom field called priority
It has 3 possible values
1 Unable to work
2 Work is impaired
3 Info/Low priority

What I want to do with a scrip is read the value of the custom field
Priority = Unable to work
$Value = Unable to work
Loop through to set the correct value with an if statement
Then assign that numeric value to the system variable priority

I have tried but nothing set the field I see under The Basic ->priority to
the value I want
$self->TicketObj->$SetPriority = $Priority;
$self->TicketObj->$Priority = $Priority;
$self->TicketObj->$SetInitialPriority = $Priority;

Scrip code (under Custom action cleanup code) I have return 1; under Custom
action preparation code

my $CFName = ‘Priority’;
my $Value = $self->TicketObj->FirstCustomFieldValue( $CFName );
my $Priority = 3;
if ($Value =~ /Unable/i)
{
$Priority = 1;
}
elsif ($Value =~ /impaired/i)
{
$Priority = 2;
}
else
{
$Priority = 3;
}

$self->TicketObj->$SetPriority = $Priority;

return 1

Thanks for any help
Janet Bass

I have a custom field called priority
It has 3 possible values
1 Unable to work
2 Work is impaired
3 Info/Low priority

Have you considered RT-Extension-PriorityAsString ?

-kevin

Yes, It seemed like overkill and had a learning curve. I was hoping there
was an easy fix in my code.On 9/23/10 11:24 AM, “Kevin Falcone” falcone@bestpractical.com wrote:

On Thu, Sep 23, 2010 at 11:15:22AM -0400, Bass, Janet E. wrote:

I have a custom field called priority
It has 3 possible values
1 Unable to work
2 Work is impaired
3 Info/Low priority

Have you considered RT-Extension-PriorityAsString ?

-kevin

What I want to do with a scrip is read the value of the custom field
Priority = Unable to work
$Value = Unable to work
Loop through to set the correct value with an if statement
Then assign that numeric value to the system variable priority

I have tried but nothing set the field I see under The Basic ->priority to
the value I want
$self->TicketObj->$SetPriority = $Priority;
$self->TicketObj->$Priority = $Priority;
$self->TicketObj->$SetInitialPriority = $Priority;

Scrip code (under Custom action cleanup code) I have return 1; under Custom
action preparation code

my $CFName = ‘Priority’;
my $Value = $self->TicketObj->FirstCustomFieldValue( $CFName );
my $Priority = 3;
if ($Value =~ /Unable/i)
{
$Priority = 1;
}
elsif ($Value =~ /impaired/i)
{
$Priority = 2;
}
else
{
$Priority = 3;
}

$self->TicketObj->$SetPriority = $Priority;

return 1

Thanks for any help
Janet Bass

RT Training in Washington DC, USA on Oct 25 & 26 2010
Last one this year – Learn how to get the most out of RT!

Janet Bass
Unix System Administration
Manufacturing Engineering Laboratory
304/Room 12
100 Bureau Dr
Mailstop 8203
Gaithersburg, MD 20899-8203
EMAIL: jbass@nist.gov
PHONE: 301-975-8425

Yes, It seemed like overkill and had a learning curve. I was hoping there
was an easy fix in my code.

$self->TicketObj->$SetPriority = $Priority;

If you want to stay with your code, look at that line.
There are at least 2 huge errors with it.
SetPriority is a method not a variable and you don’t assign to it, you
pass it an argument.

RT-Extension-PriorityAsString was written so that people who aren’t
perl programmers wouldn’t have to write this scrip.

-kevin

It is working now, Thanks
I do program in Perl it is learning RT variables that is slowing me down. I
wish there was a cheat sheet or something like that.
JanetOn 9/23/10 11:45 AM, “Kevin Falcone” falcone@bestpractical.com wrote:

On Thu, Sep 23, 2010 at 11:28:54AM -0400, Bass, Janet E. wrote:

Yes, It seemed like overkill and had a learning curve. I was hoping there
was an easy fix in my code.

$self->TicketObj->$SetPriority = $Priority;

If you want to stay with your code, look at that line.
There are at least 2 huge errors with it.
SetPriority is a method not a variable and you don’t assign to it, you
pass it an argument.

RT-Extension-PriorityAsString was written so that people who aren’t
perl programmers wouldn’t have to write this scrip.

-kevin

Janet Bass
Unix System Administration
Manufacturing Engineering Laboratory
304/Room 12
100 Bureau Dr
Mailstop 8203
Gaithersburg, MD 20899-8203
EMAIL: jbass@nist.gov
PHONE: 301-975-8425

Janet,

We have something that does exactly that, but with different CF values, of
course. We choose to name the CF a name that is different than an RT Ticket
field to avoid confusion when referring to fields and simplified the values,
but here goes:

Name: WorkFlow for Priority
Condition: User-Defined
Action: User-Defined
Template: Blank
Stage: TransactionBatch
Custom Condition:*

Set initial values

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;

Continue if the CF “Work Ability” has been changed

if ($trans->Type eq ‘CustomField’)
{my $cf = new RT::CustomField($RT::SystemUser);
$cf->LoadByName(Queue => $ticket->QueueObj->id,
Name => “Work Ability”);
return 0 unless $cf->id;
}

return 1;
Custom Action Prep:

Set initial values

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $ability = $ticket->FirstCustomFieldValue(‘Work Ability’);
my $priority;

if ($ability = ‘Unable’)
{
$priority = 1;
}
elsif ($ability = ‘impaired’)
{
$priority = 2;
}
else
{
$priority = 3;
}

$ticket->SetPriority($priority);

return 1;
Custom Action Cleanup:
return 1;

Basically the same, but I noticed you put a $ in the middle of your Set code
($self->TicketObj->$SetInitialPriority = $Priority;)

Hope this helps.

Kenn
LBNLOn Thu, Sep 23, 2010 at 8:15 AM, Bass, Janet E. janet.bass@nist.gov wrote:

I have a custom field called priority
It has 3 possible values
1 Unable to work
2 Work is impaired
3 Info/Low priority

What I want to do with a scrip is read the value of the custom field
Priority = Unable to work
$Value = Unable to work
Loop through to set the correct value with an if statement
Then assign that numeric value to the system variable priority

I have tried but nothing set the field I see under The Basic ->priority to
the value I want
$self->TicketObj->$SetPriority = $Priority;
$self->TicketObj->$Priority = $Priority;
$self->TicketObj->$SetInitialPriority = $Priority;

Scrip code (under Custom action cleanup code) I have return 1; under Custom
action preparation code

my $CFName = ‘Priority’;
my $Value = $self->TicketObj->FirstCustomFieldValue( $CFName );
my $Priority = 3;
if ($Value =~ /Unable/i)
{
$Priority = 1;
}
elsif ($Value =~ /impaired/i)
{
$Priority = 2;
}
else
{
$Priority = 3;
}

$self->TicketObj->$SetPriority = $Priority;

return 1

Thanks for any help
Janet Bass

RT Training in Washington DC, USA on Oct 25 & 26 2010
Last one this year – Learn how to get the most out of RT!