[rt-users] Problem with making a custom scrip

Bart bart at pleh.info
Wed Jul 27 03:59:28 EDT 2011


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 :)

Best regards,

Bart



2011/7/26 Bart <bart at pleh.info>

> Hi Kevin,
>
> Thanks for your reply, that turned out to be toe golden tip :D
>
> I was getting those messages in the Web UI and after changing the type to
> transaction batch it worked :D
>
> 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 :D
>
> Thanks for the help.
>
>
> Best regards,
>
> Bart
>
>
>
> 2011/7/26 Kevin Falcone <falcone at 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
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20110727/b00f4a35/attachment.htm>


More information about the rt-users mailing list