Regarding custom perl module

Moderator: crythias

Locked
vineetharalikatti
Znuny newbie
Posts: 1
Joined: 14 Jul 2016, 19:52
Znuny Version: OTRS 5.0.11
Real Name: Vineeth
Company: Computech Corporation

Regarding custom perl module

Post by vineetharalikatti »

Hello guys,

I am trying to write custom function in OTRS in which upon passing the parameters the function which I am writing should sort the tickets from different queues and write it to a file. These parameters maybe based on priority of the ticket etc etc. I just need to write this function and run in the OTRS. Can you please let me know how to achieve this task as this is my first time working with OTRS. What I know is that, in GenericAgent.pm I need to write a new sub which is like this

Code: Select all

_CustomTicket {
  my ($Self, %Param) = @_;

  # check needed stuff
  for (qw(Name UserID)) {
      if ( !$Param{$_} ) {
          $Kernel::OM->Get('Kernel::System::Log')->Log(
              Priority => 'error',
              Message  => "Need $_!"
          );
          return;
      }
  }

  return if !$DBObject->Prepare(
      SQL  => 'Select * from queue',
      Bind => [ \$Param{Name} ],
  );
  my @Data;
  open(my $fh,'>','bin/newpmfile.txt');
  while ( my @Row = $DBObject->FetchrowArray() ) {
  if($row1[3]=='2'){
    print $fh "ticket: $row1[2] AAA QUEUE \n";
  }elsif($row1[3]=='22'){
    print $fh "ticket: $row1[2] BBB QUEUE \n";
  }elsif($row1[3]=='3'){
    print $fh "ticket: $row1[2] CCC QUEUE \n";
  }elsif($row1[3]=='9'){
    print $fh "ticket: $row1[2] DDD QUEUE \n";
  }
  }
  close $fh;
},
after this what should i do. Or is this the right way to approach this problem.

If you can help me on this it would be great.

Thanks,
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Regarding custom perl module

Post by reneeb »

* Please use

Code: Select all

 tags, then your code is more readable
* You should write your own module and do not change existing files. Then an OTRS upgrade will be less pain.
* Please describe more detailed what you want to achieve
* You do not have a placeholder in your SQL statement, but you use a Bind variable. That won't work.
* Please do not use the open function. There is a WriteFile method in Kernel::System::Main
* You use the variable @Row in the while-header, but $row1[...] in the loop-body
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Locked