Problem with making a custom scrip

Hi,

I’m currently working on making a scrip for RT4 which should eventually
allow us to do the following:

  • User fills in the CF ticket type: Incident, Problem or Change.
  • User fills in the CF priority: 1, 2, 3 or 4. (in this setup we chose to
    make this a CF so that we can restrict the values entered)
  • Based on the combination of those CF’s the SLA field is automatically
    filled with the appropriate SLA for that combo.
    • The SLA CF has these fixed values: Urgent, Normal, Low.
    • It’s the SLA field that you get from the plugin.

I found this scrip on the wiki which almost does what I want:

http://requesttracker.wikia.com/wiki/CreatePriorityBasedOnCustomFieldValues

As a result I’m now looking at making a simple statement which sets the SLA
based on te ticket type alone (for now).
When that part is working I would expect that expanding the scrip to also
incorporate the priority wouldn’t be too difficult.

This is what I’ve come up with so far:

  • Condition: On status change
  • Action: User defined
  • Template: Global Template: Transaction
  • Stage: TransactionCreate

Custom condition:
Custom action preparation code: return 1;
Custom action cleanup code:

my $my_type = $self->TicketObj->CustomFieldValues(‘Type’);

my $my_sla = ‘Urgent’ if ($my_type =~ /^I/);
my $my_sla = ‘Normal’ if ($my_type =~ /^C/);
my $my_sla = ‘Low’ if ($my_type =~ /^P/);
$self->TicketObj->AddCustomFieldValue( Field => ‘SLA’, Value => $my_sla );

At this point I’m kinda stuck, no matter how I fill in this part it always
sets the SLA field to Normal regardless of the content in the CF type.

Can someone point me in the right direction for this? I’d love to get this
to work :slight_smile:

Best regards,

Bart

Dnia 2011-07-26, wto o godzinie 10:22 +0200, Bart pisze:
(…)

    my $my_type = $self->TicketObj->CustomFieldValues('Type');

Use $self->TicketObj->FirstCustomFieldValue(‘Type’) instead.

Regards,
Robert Wysocki
CONTIUM S.A., http://www.contium.pl

Hi Robert,

Thanks for the reply, I’ve changed that setting but it doesn’t seem to fully
solve my problem (I do notice a difference).

I’ve modified the scrip a little, it now looks like this:

my $my_type = $self->TicketObj->FirstCustomFieldValue(‘Type’);

if ($my_type =~ /^I/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Urgent’); };
if ($my_type =~ /^C/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Normal’); };
if ($my_type =~ /^P/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Low’); };

The first problem I have is that the SLA is already set to the value
"Normal", I see the scrip running but it keeps saying “Set SLA Low to
Normal” or similar for Urgent (normal is ignored). So I get a feeling it
does something, but it doesn’t actually change the content of the SLA field.

Maybe it’s the type of CF that the SLA field is, it’s a dropbox with the
three options Urgent, Normal and Low. But I thought it shouldn’t matter?!

The second problem is that if the SLA field is set to (no value) then the
scrip gives the error “Low is no longer a value for custom field SLA”, which
could be the same issue as the first? Not able to fill the actual field?

Any thoughts on this? (the above code is a little different but I get the
same results as the first code)

Best regards,

Bart2011/7/26 Robert Wysocki robert.wysocki@contium.pl

Dnia 2011-07-26, wto o godzinie 10:22 +0200, Bart pisze:
(…)

    my $my_type = $self->TicketObj->CustomFieldValues('Type');

Use $self->TicketObj->FirstCustomFieldValue(‘Type’) instead.

Regards,

Robert Wysocki
CONTIUM S.A., http://www.contium.pl


2011 Training: http://bestpractical.com/services/training.html

hi,
shouldn’t you remove the trailing ; at the end of the line on the if
statement ?
if ($my_type =~ /^I/) {
$self->TicketObj->AddCustomFieldValue(Field => ‘SLA’, Value => ‘Urgent’);
};
should be
if ($my_type =~ /^I/) {
$self->TicketObj->AddCustomFieldValue(Field => ‘SLA’, Value => ‘Urgent’);
}

Rapha�l MOUNEYRES

Bart bart@pleh.info
Envoy� par : rt-users-bounces@lists.bestpractical.com
26/07/2011 14:41

A
rt-users@lists.bestpractical.com
cc

Objet
Re: [rt-users] Problem with making a custom scrip

Hi Robert,

Thanks for the reply, I’ve changed that setting but it doesn’t seem to
fully solve my problem (I do notice a difference).

I’ve modified the scrip a little, it now looks like this:

my $my_type = $self->TicketObj->FirstCustomFieldValue(‘Type’);
if ($my_type =~ /^I/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Urgent’); };
if ($my_type =~ /^C/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Normal’); };
if ($my_type =~ /^P/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Low’); };

The first problem I have is that the SLA is already set to the value
"Normal", I see the scrip running but it keeps saying “Set SLA Low to
Normal” or similar for Urgent (normal is ignored). So I get a feeling it
does something, but it doesn’t actually change the content of the SLA
field.

Maybe it’s the type of CF that the SLA field is, it’s a dropbox with the
three options Urgent, Normal and Low. But I thought it shouldn’t matter?!

The second problem is that if the SLA field is set to (no value) then the
scrip gives the error “Low is no longer a value for custom field SLA”,
which could be the same issue as the first? Not able to fill the actual
field?

Any thoughts on this? (the above code is a little different but I get the
same results as the first code)

Best regards,

Bart

Dnia 2011-07-26, wto o godzinie 10:22 +0200, Bart pisze:
(…)

    my $my_type = $self->TicketObj->CustomFieldValues('Type');

Use $self->TicketObj->FirstCustomFieldValue(‘Type’) instead.

Regards,
Robert Wysocki
CONTIUM S.A., http://www.contium.pl

2011 Training: http://bestpractical.com/services/training.html

2011 Training: http://bestpractical.com/services/training.html

" Ce courriel et les documents qui lui sont joints peuvent contenir des
informations confidentielles ou ayant un caract�re priv�. S’ils ne vous sont
pas destin�s, nous vous signalons qu’il est strictement interdit de les
divulguer, de les reproduire ou d’en utiliser de quelque mani�re que ce
soit le contenu. Si ce message vous a �t� transmis par erreur, merci d’en
informer l’exp�diteur et de supprimer imm�diatement de votre syst�me
informatique ce courriel ainsi que tous les documents qui y sont attach�s."

" This e-mail and any attached documents may contain confidential or
proprietary information. If you are not the intended recipient, you are
notified that any dissemination, copying of this e-mail and any attachments
thereto or use of their contents by any means whatsoever is strictly
prohibited. If you have received this e-mail in error, please advise the
sender immediately and delete this e-mail and all attached documents
from your computer system."

Hi Raphaël,

I gave that a try just now, doesn’t seem to make any difference :frowning:

Best regards,

Bart2011/7/26 Raphaël MOUNEYRES raphael.mouneyres@sagemcom.com

hi,
shouldn’t you remove the trailing ; at the end of the line on the if
statement ?
if ($my_type =~ /^I/) { $self->TicketObj->AddCustomFieldValue(Field
=> ‘SLA’, Value => ‘Urgent’); };
should be
if ($my_type =~ /^I/) { $self->TicketObj->AddCustomFieldValue(Field
=> ‘SLA’, Value => ‘Urgent’); }

Raphaël MOUNEYRES

Bart bart@pleh.info
Envoyé par : rt-users-bounces@lists.bestpractical.com

26/07/2011 14:41
A
rt-users@lists.bestpractical.com
cc
Objet
Re: [rt-users] Problem with making a custom scrip

Hi Robert,

Thanks for the reply, I’ve changed that setting but it doesn’t seem to
fully solve my problem (I do notice a difference).

I’ve modified the scrip a little, it now looks like this:

my $my_type = $self->TicketObj->FirstCustomFieldValue(‘Type’);
if ($my_type =~ /^I/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Urgent’); };
if ($my_type =~ /^C/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Normal’); };
if ($my_type =~ /^P/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Low’); };

The first problem I have is that the SLA is already set to the value
"Normal", I see the scrip running but it keeps saying “Set SLA Low to
Normal” or similar for Urgent (normal is ignored). So I get a feeling it
does something, but it doesn’t actually change the content of the SLA field.

Maybe it’s the type of CF that the SLA field is, it’s a dropbox with the
three options Urgent, Normal and Low. But I thought it shouldn’t matter?!

The second problem is that if the SLA field is set to (no value) then the
scrip gives the error “Low is no longer a value for custom field SLA”,
which could be the same issue as the first? Not able to fill the actual
field?

Any thoughts on this? (the above code is a little different but I get the
same results as the first code)

Best regards,

Bart

2011/7/26 Robert Wysocki <robert.wysocki@contium.plrobert.wysocki@contium.pl

Dnia 2011-07-26, wto o godzinie 10:22 +0200, Bart pisze:
(…)

    my $my_type = $self->TicketObj->CustomFieldValues('Type');

Use $self->TicketObj->FirstCustomFieldValue(‘Type’) instead.

Regards,

Robert Wysocki
CONTIUM S.A., http://www.contium.pl http://www.contium.pl/


2011 Training: http://bestpractical.com/services/training.htmlhttp://bestpractical.com/services/training.html


2011 Training: http://bestpractical.com/services/training.html

" Ce courriel et les documents qui lui sont joints peuvent contenir des
informations confidentielles ou ayant un caractère privé. S’ils ne vous sont
pas destinés, nous vous signalons qu’il est strictement interdit de les
divulguer, de les reproduire ou d’en utiliser de quelque manière que ce
soit le contenu. Si ce message vous a été transmis par erreur, merci d’en
informer l’expéditeur et de supprimer immédiatement de votre système
informatique ce courriel ainsi que tous les documents qui y sont attachés."

                           ******

" This e-mail and any attached documents may contain confidential or
proprietary information. If you are not the intended recipient, you are
notified that any dissemination, copying of this e-mail and any attachments
thereto or use of their contents by any means whatsoever is strictly
prohibited. If you have received this e-mail in error, please advise the
sender immediately and delete this e-mail and all attached documents
from your computer system."

The first problem I have is that the SLA is already set to the value “Normal”, I see the scrip
running but it keeps saying “Set SLA Low to Normal” or similar for Urgent (normal is ignored).
So I get a feeling it does something, but it doesn’t actually change the content of the SLA
field.
Maybe it’s the type of CF that the SLA field is, it’s a dropbox with the three options Urgent,
Normal and Low. But I thought it shouldn’t matter?!
The second problem is that if the SLA field is set to (no value) then the scrip gives the
error “Low is no longer a value for custom field SLA”, which could be the same issue as the
first? Not able to fill the actual field?
Any thoughts on this? (the above code is a little different but I get the same results as the
first code)

Where do you see these messages, in the webui? Are you doing this on
create or from the Basics page and setting the SLA to normal or unset
there?

You may need to switch your scrip type to transactionbatch to it runs
after the web updates finish.

-kevin

Hi Kevin,

Thanks for your reply, that turned out to be toe golden tip :smiley:

I was getting those messages in the Web UI and after changing the type to
transaction batch it worked :smiley:

So to summarize, here’s the end result that worked perfectly for me:

  • Condition: On Transaction
  • Action: User Defined
  • Template: Global Template: Transaction
  • Stage: TransactionBatch
  • Custom condition: (empty)
  • Custom action preparation code: return 1;
  • Custom action cleanup code:

my $my_type = $self->TicketObj->FirstCustomFieldValue(‘Type’);

if ($my_type =~ /^I/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Urgent’); }
if ($my_type =~ /^C/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Normaal’); }
if ($my_type =~ /^P/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Laag’); }

All I have to do now is expand the scrip to also check another field, but
that shouldn’t be a problem now that this is working :smiley:

Thanks for the help.

Best regards,

Bart2011/7/26 Kevin Falcone falcone@bestpractical.com

On Tue, Jul 26, 2011 at 02:40:21PM +0200, Bart wrote:

The first problem I have is that the SLA is already set to the value
"Normal", I see the scrip
running but it keeps saying “Set SLA Low to Normal” or similar for
Urgent (normal is ignored).
So I get a feeling it does something, but it doesn’t actually change
the content of the SLA
field.
Maybe it’s the type of CF that the SLA field is, it’s a dropbox with
the three options Urgent,
Normal and Low. But I thought it shouldn’t matter?!
The second problem is that if the SLA field is set to (no value) then
the scrip gives the
error “Low is no longer a value for custom field SLA”, which could be
the same issue as the
first? Not able to fill the actual field?
Any thoughts on this? (the above code is a little different but I get
the same results as the
first code)

Where do you see these messages, in the webui? Are you doing this on
create or from the Basics page and setting the SLA to normal or unset
there?

You may need to switch your scrip type to transactionbatch to it runs
after the web updates finish.

-kevin


2011 Training: http://bestpractical.com/services/training.html

Hi,

I’ve finished the scrip with my initial purpose, which was to set the ticket
type (incident, problem or change) along with the priority (1 to 5) and
based on those two values set the SLA field (from the SLA plugin/addon).

The result is listed below, this basically does the following:

  • CF Type && CF Prio = SLA
  • System Prio = CF Prio

The reason why I’m using a CF for the prio is to make it easy for our
personell to select a value upon creating a ticket + it forces them to
select a fixed vlaue (dropdown) which makes it a little faster as well.
In addition I’m also making sure the system prio field is set to the same
value as the CF Prio.

Details for this scrip are below:

  • Condition: On Transaction
  • Action: User Defined
  • Template: Global Template: Transaction
  • Stage: TransactionBatch
  • Custom condition: (empty)
  • Custom action preparation code: return 1;
  • Custom action cleanup code:

Set the value of the CF’s Type and Prio to a variable

my $my_type = $self->TicketObj->FirstCustomFieldValue(‘Type’);
my $my_prio = $self->TicketObj->FirstCustomFieldValue(‘Prio’);

Change the system’s Prio value to the value inside CF Prio

$self->TicketObj->SetPriority ($my_prio);

INCIDENT

if ($my_type == ‘Incident’ && $my_prio == ‘1’) {
$self->TicketObj->AddCustomFieldValue(Field => ‘SLA’, Value => ‘Urgent’); }
if ($my_type == ‘Incident’ && $my_prio == ‘2’) {
$self->TicketObj->AddCustomFieldValue(Field => ‘SLA’, Value => ‘Normal’); }
if ($my_type == ‘Incident’ && $my_prio == ‘3’) {
$self->TicketObj->AddCustomFieldValue(Field => ‘SLA’, Value => ‘Low’); }

CHANGE

if ($my_type == ‘Change’ && $my_prio == ‘1’) {
$self->TicketObj->AddCustomFieldValue(Field => ‘SLA’, Value => ‘Urgent’); }
if ($my_type == ‘Change’ && $my_prio == ‘2’) {
$self->TicketObj->AddCustomFieldValue(Field => ‘SLA’, Value => ‘Normal’); }
if ($my_type == ‘Change’ && $my_prio == ‘3’) {
$self->TicketObj->AddCustomFieldValue(Field => ‘SLA’, Value => ‘Low’); }

PROBLEM

if ($my_type == ‘Problem’ && $my_prio == ‘1’) {
$self->TicketObj->AddCustomFieldValue(Field => ‘SLA’, Value => ‘Urgent’); }
if ($my_type == ‘Problem’ && $my_prio == ‘2’) {
$self->TicketObj->AddCustomFieldValue(Field => ‘SLA’, Value => ‘Normal’); }
if ($my_type == ‘Problem’ && $my_prio == ‘3’) {
$self->TicketObj->AddCustomFieldValue(Field => ‘SLA’, Value => ‘Low’); }

Now all that’s left for me is to expand the SLA’s to contain numbers instead
of names ( e.g. SLA 4 would mean 4 hours, could be used for both Incident
and Change).
But those are filling in the details, the above could be easily changed and
perfected to trigger the proper SLA value.

Thanks again for all the help, sometimes your just banging your head on
something simple and this just happend to be one of those things :slight_smile:

Best regards,

Bart2011/7/26 Bart bart@pleh.info

Hi Kevin,

Thanks for your reply, that turned out to be toe golden tip :smiley:

I was getting those messages in the Web UI and after changing the type to
transaction batch it worked :smiley:

So to summarize, here’s the end result that worked perfectly for me:

  • Condition: On Transaction
  • Action: User Defined
  • Template: Global Template: Transaction
  • Stage: TransactionBatch
  • Custom condition: (empty)
  • Custom action preparation code: return 1;
  • Custom action cleanup code:

my $my_type = $self->TicketObj->FirstCustomFieldValue(‘Type’);

if ($my_type =~ /^I/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Urgent’); }
if ($my_type =~ /^C/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Normaal’); }
if ($my_type =~ /^P/) { $self->TicketObj->AddCustomFieldValue(Field =>
‘SLA’, Value => ‘Laag’); }

All I have to do now is expand the scrip to also check another field, but
that shouldn’t be a problem now that this is working :smiley:

Thanks for the help.

Best regards,

Bart

2011/7/26 Kevin Falcone falcone@bestpractical.com

On Tue, Jul 26, 2011 at 02:40:21PM +0200, Bart wrote:

The first problem I have is that the SLA is already set to the value
"Normal", I see the scrip
running but it keeps saying “Set SLA Low to Normal” or similar for
Urgent (normal is ignored).
So I get a feeling it does something, but it doesn’t actually change
the content of the SLA
field.
Maybe it’s the type of CF that the SLA field is, it’s a dropbox with
the three options Urgent,
Normal and Low. But I thought it shouldn’t matter?!
The second problem is that if the SLA field is set to (no value) then
the scrip gives the
error “Low is no longer a value for custom field SLA”, which could be
the same issue as the
first? Not able to fill the actual field?
Any thoughts on this? (the above code is a little different but I get
the same results as the
first code)

Where do you see these messages, in the webui? Are you doing this on
create or from the Basics page and setting the SLA to normal or unset
there?

You may need to switch your scrip type to transactionbatch to it runs
after the web updates finish.

-kevin


2011 Training: http://bestpractical.com/services/training.html

I’ve finished the scrip with my initial purpose, which was to set the ticket
type (incident, problem or change) along with the priority (1 to 5) and
based on those two values set the SLA field (from the SLA plugin/addon).
The result is listed below, this basically does the following:

CF Type && CF Prio = SLA
System Prio = CF Prio

The reason why I’m using a CF for the prio is to make it easy for our
personell to select a value upon creating a ticket + it forces them to
select a fixed vlaue (dropdown) which makes it a little faster as well.
In addition I’m also making sure the system prio field is set to the same
value as the CF Prio.

Instead of using CF for priority you can use PriorityAsString extension.

Best regards, Ruslan.