Register own module - how?

Moderator: crythias

Locked
shostakovich
Znuny advanced
Posts: 146
Joined: 11 Apr 2011, 08:11
Znuny Version: 3.2.5

Register own module - how?

Post by shostakovich »

I'm writing a module which does this:

- Fix a Tickets Priority value on TicketCreate depending on TicketFreeText14 value (Impact) and Ticket type. Currently I'm doing this with cron and GenericAgent, which is not nice.

I do not speak Perl fluently and need to test a bit and do debugging fun, so I'm using some HistoryAdd things in the module, BUT:

Nothing happens, I expected some http 500 Internal Servcer Error :) - I think the module is not properly registered.

- To Config.pm I added:

Code: Select all

    $Self->{'Ticket::EventModulePost'}->{'137-FixPriority'} =  {
      'Event' => '(TicketCreate)',
      'Module' => 'Kernel::System::Ticket::Event::FixPriority'
    };
- The module resides in ./otrs/Kernel/System/Ticket/Event/FixPriority.pm
- I've restarted Apache

Anything else I have to do?

Where can I see if the module is actually registered? Currently I do not know if it's either not registered or not triggered.

TIA
Michael
renee
Znuny expert
Posts: 241
Joined: 06 Feb 2009, 11:15
Znuny Version: 3.0.x
Company: Perl-Services.de
Contact:

Re: Register own module - how?

Post by renee »

Instead of HistoryAdd, you should use

Code: Select all

$Self->{LogObject}->Log( Priority => 'error', Message => 'Whatever you want to print' );
If you use a logfile, you can do a tail on it...

Code: Select all

tail -f /path/to/otrs.log
Please do this:

Code: Select all

> cd /opt/otrs/
> perl -IKernel/cpan-lib/ -cw Kernel/System/Ticket/Event/FixPriority.pm
When it says "Syntax OK", you won't get a 500 Internal Server Error

Next: use logging at the beginning of the subroutine "Run" (right after "my ($Self,%Param) = @_"). Create a ticket then and if the log message appears in you log, you know that your module is triggered.
Need a Perl/OTRS developer? You can contact me at info@perl-services.de
shostakovich
Znuny advanced
Posts: 146
Joined: 11 Apr 2011, 08:11
Znuny Version: 3.2.5

Re: Register own module - how?

Post by shostakovich »

Thanks Renee -- after some tests I see it already was registered - now the fun can begin. Actually I just need to manage to get TicketFreeText values and set Priority Values.
renee
Znuny expert
Posts: 241
Joined: 06 Feb 2009, 11:15
Znuny Version: 3.0.x
Company: Perl-Services.de
Contact:

Re: Register own module - how?

Post by renee »

Can you post your code and describe in detail what you want to achieve?
Need a Perl/OTRS developer? You can contact me at info@perl-services.de
shostakovich
Znuny advanced
Posts: 146
Joined: 11 Apr 2011, 08:11
Znuny Version: 3.2.5

Re: Register own module - how?

Post by shostakovich »

Thanks for your support! I want to do this (pseudo code), it's executed on TicketCreate:

Code: Select all

1. if ( $Ticket{Type} eq 'Service-Request' ) {
2.  IF ImpactID == 6 {
3.   set PriorityID=1
4.  }
5.  ELSIF ((ImpactID >6) && (ImpactID<9)){
6.   set PriorityID=2
7.  }
8. }
I'm almost done: I've managed to set the Prio-ID (with TicketPrioritySet) - I just have to sort out how to retrieve the ImpactID (TicketFreeText14 value) for lines 2 and 5.
MichaelR
Znuny expert
Posts: 250
Joined: 12 Oct 2010, 01:35
Znuny Version: 3.0.9
Company: LRS Health

Re: Register own module - how?

Post by MichaelR »

TicketObject::TicketGet() will do that for you :)
OTRS: 3.0.9 & ITSM 3.0.4 - OS: Windows 7 - DB: MySQL - Heaps of random/useful hacks :)
[Major Code Changes]
ArticleFreeTime1-3
Ability to search ArticleFreeText
shostakovich
Znuny advanced
Posts: 146
Joined: 11 Apr 2011, 08:11
Znuny Version: 3.2.5

Re: Register own module - how?

Post by shostakovich »

Why doesn't this retrieve the Impact value (TicketFreeText14)?

Code: Select all

my %Ticket = $Self->{TicketObject}->TicketGet( TicketID => $Param{Data}->{TicketID} );
if ( $Ticket{TicketFreeText14} == '7' ) { ...
I checked: $Ticket{TicketFreeText14} is empty, but in reality it is not. According to http://dev.otrs.org/3.0/Kernel/System/Ticket.html this should work, IMO. With $Ticket{TypeID} etc. I get a value in return... What am I doing wrong?

TIA :)
Michael
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Register own module - how?

Post by crythias »

You need to have a UserID (such as UserID=>1) in your TicketGet, because it needs to know what permission to get on behalf of.

Get ticket info
my %Ticket = $TicketObject->TicketGet(
TicketID => 123,
UserID => 123,
);
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
shostakovich
Znuny advanced
Posts: 146
Joined: 11 Apr 2011, 08:11
Znuny Version: 3.2.5

Re: Register own module - how?

Post by shostakovich »

Thanks, I already got this solved... http://forums.otrs.org/viewtopic.php?f=62&t=10992

The problem is, if you submit a phone ticket and your trigger is "TicketCreate", at that moment the TicketFreeText fields are still not known even though you defined everything in the "new phone ticket" window... Makes things difficult!
ferrosti
Znuny superhero
Posts: 723
Joined: 10 Oct 2007, 14:30
Znuny Version: 3.0
Location: Hamburg, Germany

Re: Register own module - how?

Post by ferrosti »

Can you help yourself using the ArticleFreeText fields instead?
You´d then still need a second job to do what you want.
openSuSE on ESX
IT-Helpdesk: OTRS 3.0
Customer Service: OTRS 3.0 (upgraded from 2.3)
Customer Service (subsidiary): OTRS 3.0
+additional test and development systems
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Register own module - how?

Post by crythias »

You could choose ArticleCreate, perhaps. Just make sure you're looking at an articlecreate of a new ticket (sorry, I'm pulling this out of my head at the moment).
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
shostakovich
Znuny advanced
Posts: 146
Joined: 11 Apr 2011, 08:11
Znuny Version: 3.2.5

Re: Register own module - how?

Post by shostakovich »

crythias wrote:You could choose ArticleCreate, perhaps. Just make sure you're looking at an articlecreate of a new ticket (sorry, I'm pulling this out of my head at the moment).
In AdminNotificationEvent, you mean Event:ArticleCreate plus the ArticleType at the bottom of the page? But AFAICS I'd have to either chose email-external (for incoming mail) or phone (for phone tickets), but: they may occur more often in a tickets lifetime, I think?
Locked