get id of connected agent in custom module

English! place to talk about development, programming and coding
Post Reply
gsalin
Znuny newbie
Posts: 36
Joined: 10 Mar 2023, 16:38
Znuny Version: znuny 6.5.1
Real Name: Gérald Salin
Company: INRAE - GeT-PlaGe

get id of connected agent in custom module

Post by gsalin »

Hi,
I'm running a custom module (i.e. Custom/GeTModules/AutoWatch.pm) through generic agent, called when a new article is created.

Is there a way to get the id of the agent who is connected and who added the article that called the generic agent?

Thank you for your help.

Gérald
--
znuny 6.5.6
postgresql 13
Rocky 8
root
Administrator
Posts: 3966
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: get id of connected agent in custom module

Post by root »

Hi Gérald,

it might be UserID but to do something on an article creation I recommend using an event module. Here a small example with code: https://github.com/znuny/Znuny/blob/rel ... rCreate.pm and then you need the module registration like this:

Code: Select all

  <Setting Name="Ticket::EventModulePost###8000-MyEventModule" Required="0" Valid="1">
        <Description Translatable="1">Just say what it does.</Description>
        <Navigation>Core::Event::Ticket</Navigation>
        <Value>
            <Hash>
                <Item Key="Module">Kernel::System::Ticket::Event::MyModule</Item>
                <Item Key="Event">ArticleCreate</Item>
                <Item Key="Transaction">1</Item>
            </Hash>
        </Value>
    </Setting>
- Roy
Znuny and Znuny LTS running on CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Use a test system - always.

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know where it goes ?
gsalin
Znuny newbie
Posts: 36
Joined: 10 Mar 2023, 16:38
Znuny Version: znuny 6.5.1
Real Name: Gérald Salin
Company: INRAE - GeT-PlaGe

Re: get id of connected agent in custom module

Post by gsalin »

Hi Roy,
thank you for your help....
I will explain my need, and what I've done so far..

My first goal : allow an agent who answers a ticket to become watcher by default
TO achieve this,
  • I created a custom module, called via Generic AGent on article creation
    I created a dynamic field "Do not watch this ticket" which is displayed on new article creation : if the agent select this dynamic field, he is not defined, or removed from watchers, else he is added as a watcher on this ticket
My custom module can be more efficient. Currently, it extracts last article of the ticket, get the id of the agent who sent the article and add the userid as watcher (or remove it according to the dynamic field value)....but it works

I would like to do the same thing without the need to send an email, through bulk actions.

My new goal : allow an agent to unwatch multiple tickets through bulk actions, without writing a new article
To achieve this :
  • select one or more tickets
    click on Bulk actions
    display my dynamic field "Do not watch this ticket"
    call a generic agent on ticket dynamic field "Do not watch this ticket" update
if "Do not watch this ticket" is selected, get the userID of the connected user, get the ticketId and unsuscribe the user.....

My problem : get the userId f the connected agent....

Thank you for your help

Gérald
--
znuny 6.5.6
postgresql 13
Rocky 8
Post Reply