how to create a bouton link to a perl method in template

Moderator: crythias

Post Reply
draugael
Znuny newbie
Posts: 8
Joined: 13 Mar 2018, 16:56
Znuny Version: 6.0.5

how to create a bouton link to a perl method in template

Post by draugael »

I wish create a bouton link to a perl method in my perl module in the template.

Thanks in advance!!!
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: how to create a bouton link to a perl method in template

Post by reneeb »

Can you describe more detailed what you want to achieve? Where should be the button (which page, where on that page)? Is your module an OTRS frontend module?
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
draugael
Znuny newbie
Posts: 8
Joined: 13 Mar 2018, 16:56
Znuny Version: 6.0.5

Re: how to create a bouton link to a perl method in template

Post by draugael »

I want add this button on the action bar on the template Agent Ticket Zoom for change the owner for a specific owner. I have already a functional script for the task:

Code: Select all

 #get queue name
    my $QueueID = $TicketObject->TicketQueueID(
        TicketID => $Param{TicketID},
    );


    my $Queue = $QueueObject->QueueLookup(
        QueueID => $QueueID
    );

    #get level 1 user

    my $RoleID = $GroupObject->RoleLookup(
        Role => "assistant $Queue niveau 2",
    );

    my %User = $GroupObject->PermissionRoleUserGet(
        RoleID => $RoleID
    );

    my $UserLevelOne = (values %User)[0];

    #change ticketOwner
    my $Success = $TicketObject->TicketOwnerSet(
        TicketID => $Param{TicketID},
        NewUser  => $UserLevelOne,
        UserID   => $OwnerID,
    );
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: how to create a bouton link to a perl method in template

Post by reneeb »

You need those files (replace the MySetOwner with a name you choose, e.g. ):

* Kernel/Config/Files/MySetOwner.xml
* Kernel/Modules/AgentTicketMySetOwner.pm

The config file is needed to create the "button" in the ticket menu.

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<otrs_config version="2.0" init="Config">
    <Setting Name="Ticket::Frontend::MenuModule###101-SetOwner" Required="0" Valid="1">
        <Description Translatable="1">Shows a link in the menu to set the level1 owner</Description>
        <Navigation>Frontend::Agent::View::TicketZoom::MenuModule</Navigation>
        <Value>
            <Hash>
                <Item Key="Module">Kernel::Output::HTML::TicketMenu::Generic</Item>
                <Item Key="Name" Translatable="1">Set level 1 owner</Item>
                <Item Key="Description" Translatable="1">Set level 1 owner</Item>
                <Item Key="Action">AgentTicketMySetOwner;TicketID=[% Data.TicketID | html %]</Item>
                <Item Key="Target"></Item>
                <Item Key="ClusterName" Translatable="1">People</Item>
                <Item Key="ClusterPriority">005</Item>
            </Hash>
        </Value>
    </Setting>
    <Setting Name="Frontend::Module###AgentTicketMySetOwner" Required="0" Valid="1">
        <Description Translatable="1">Frontend module registration for the agent interface.</Description>
        <Navigation>Frontend::Agent::ModuleRegistration</Navigation>
        <Value>
            <Item ValueType="FrontendRegistration">
                <Hash>
                    <Item Key="Group">
                    </Item>
                    <Item Key="GroupRo">
                    </Item>
                    <Item Key="Description" Translatable="1">Set level1 owner.</Item>
                    <Item Key="Title" Translatable="1">Set level1 owner</Item>
                    <Item Key="NavBarName">Ticket</Item>
                </Hash>
            </Item>
        </Value>
    </Setting>
 </otrs_config>
Then the frontend module:

Code: Select all

package Kernel::Modules::AgentTicketMySetOwner;

use strict;
use warnings;

use Kernel::Language qw(Translatable);

our $ObjectManagerDisabled = 1;

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {%Param};
    bless( $Self, $Type );

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;
    
    my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request');
    my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
    my $QueueObject = $Kernel::OM->Get('Kernel::System::Queue');
    my $GroupObject = $Kernel::OM->Get('Kernel::System::Group');
    
    my $TicketID = $ParamObject->GetParam( Param => 'TicketID' );
    
    # HINT: YOU SHOULD CHECK PERMISSIONS HERE
    
    #get queue name
    my $QueueID = $TicketObject->TicketQueueID(
        TicketID => $TicketID,
    );

    my $Queue = $QueueObject->QueueLookup(
        QueueID => $QueueID
    );

    #get level 1 user

    my $RoleID = $GroupObject->RoleLookup(
        Role => "assistant $Queue niveau 2",
    );

    my %User = $GroupObject->PermissionRoleUserGet(
        RoleID => $RoleID
    );

    my $UserLevelOne = (values %User)[0];

    #change ticketOwner
    my $Success = $TicketObject->TicketOwnerSet(
        TicketID => $TicketID,
        NewUser  => $UserLevelOne,
        UserID   => $OwnerID,
    );
    
    return $LayoutObject->Redirect(
        OP => 'Action=AgentTicketZoom&TicketID=' . $TicketID,
    );
}

1;
After copying those files (but don't forget to copy those files on an OTRS upgrade) run

Code: Select all

perl bin/otrs.Console.pl Maint::Config::Rebuild
Maybe this helps.
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
Post Reply