Run the event of TicketStateUpdate only one time

English! place to talk about development, programming and coding
Post Reply
ndhvu275
Znuny advanced
Posts: 139
Joined: 06 Nov 2012, 09:02
Znuny Version: 3.x, 4.x and 5.x
Real Name: Vu Nguyen
Company: INFOdation
Location: Netherlands
Contact:

Run the event of TicketStateUpdate only one time

Post by ndhvu275 »

Hi all,

The requirement wants to update state for parent ticket when the state of child ticket is updated. For example, I have a parent ticket and a child ticket (split to create), the states of both are "new". When I update state of child ticket is "open" => auto update state of parent is "open" as well.

My current development, I'm using event of TicketStateUpdate (create an event file is *.pm in \Kernel\Ticket\Event\ and a config file to catch this event). So, when update a state of ticket, everything in event file will be implemented.

And my issue is how to prevent updating of state run in multi sub level in paren/child ticket. For example, there is a parent <- a child ticket <- a sub child ticket <- a sub sub child ticket, when update state of a sub sub child ticket, JUST ALLOW to update one level up for state of a sub child ticket. DO NOT allow to update state of a child ticket/ parent child.

Here is my coding in event file

Code: Select all

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

    # check needed stuff
    for (qw(Data Event Config)) {
        if ( !$Param{$_} ) {
            $Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
            return;
        }
    }
	
    if ( $Param{Event} eq 'TicketStateUpdate' ) {
		# check existing parent tickets
		my %LinkList = $Self->{LinkObject}->LinkKeyListWithData(
			Object1   => 'Ticket',
			Key1      => $Param{Data}->{TicketID},
			Object2   => 'Ticket',
			Type      => 'ParentChild',
			Direction => 'Source',
			State     => 'Valid',
			UserID    => 1,
		);
		
		if (%LinkList) {
			# get child ticket
			my %ChildTicket = $Self->{TicketObject}->TicketGet(
				TicketID => $Param{Data}->{TicketID},
				UserID   => $Param{UserID},
			);
			
			# update state foreach parent ticket
			for my $ParentTicketID ( keys %LinkList ) {				
				if ($ChildTicket{State}) {					
					$Self->{TicketObject}->TicketStateSet(
						TicketID => $ParentTicketID,
						State  => $ChildTicket{State},
						UserID   => 1,
					);
				}
			}
		}		
    }

    return 1;
}
I'm thinking about using cache or session in event file as a counter to recognize it's run already or not, but don't know how to use. Or do you know what elses are better solutions, please help me.

Thanks in adv

Vu Nguyen
OTRS 3.x, 4.x on CentOS/Windows
MySQL database
External customer backend with MySQL, MSSQL
Customization
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Run the event of TicketStateUpdate only one time

Post by crythias »

ndhvu275 wrote:The requirement wants to update state for parent ticket when the state of child ticket is updated
This is (IMO) backwards. Your parent should control the children. If you're changing the Parent because of process flow, you may want a different method of handling this.

Also, if I"m reading the dev and code, it could be that your keys and values are swapped. (child => Parent)

I could be wrong, though.
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
ndhvu275
Znuny advanced
Posts: 139
Joined: 06 Nov 2012, 09:02
Znuny Version: 3.x, 4.x and 5.x
Real Name: Vu Nguyen
Company: INFOdation
Location: Netherlands
Contact:

Re: Run the event of TicketStateUpdate only one time

Post by ndhvu275 »

Hi Crythias,

Thanks for your reply, it's really a process I need, the tickets are monitored/resovled by a partner of supplier, if these tickets is pure technical which can not resolved by this partner, then they will split into tasks will be resolved by supplier (level one). It maybe supplier can not resolved as well, then they will split int sub-tasks will be resolved by a solution group (level two) ... level three, four...So, what can be done on sub-level that would be monitored by supervisor (just one level up)

However, I don't understand the key and value you're mention, can you explain more. Btw, this issue is resolved by adding a condition more is current userID != 1 in IF clause like below. Because the auto updating state for parents will be performed by OTRS Admin (UserID =1)

Code: Select all

if ( ($Param{Event} eq 'TicketStateUpdate') && ($Param{UserID} != 1) ) {
Thanks,

Vu Nguyen
OTRS 3.x, 4.x on CentOS/Windows
MySQL database
External customer backend with MySQL, MSSQL
Customization
tto
Znuny wizard
Posts: 315
Joined: 09 Jan 2007, 15:24
Znuny Version: OTRS 5.0.x
Real Name: Torsten
Company: c.a.p.e. IT GmbH
Location: Chemnitz
Contact:

Re: Run the event of TicketStateUpdate only one time

Post by tto »

ndhvu275 wrote:
And my issue is how to prevent updating of state run in multi sub level in paren/child ticket. For example, there is a parent <- a child ticket <- a sub child ticket <- a sub sub child ticket, when update state of a sub sub child ticket, JUST ALLOW to update one level up for state of a sub child ticket. DO NOT allow to update state of a child ticket/ parent child.

Do you use "Transaction" in your event registration? I just had a similar situation where one event handler was supposed to trigger another one but it didn't. After changing the event configuration to Transaction=0 it did. I Haven'T had the time to find out the exact reason for this behavior - it might be related to some other core modifications. But you can give it a try, to set Transaction => 1.

Otherwise your event handler must check that the event is only performed if the ticket is a root-node in the ticket link-graph, so you should check that the ticket is parent, but no child to another ticket.

regards, T.
--
KIX 17.x (fork of OTRS)
Professional KIX-, or OTRS-integration, development and consulting by c.a.p.e. IT - http://www.cape-it.de
For questions and hints regarding KIX(4OTRS) please go to https://forum.kixdesk.com/
Bei Fragen und Hinweisen zu KIX(4OTRS) bitte an https://forum.kixdesk.com/ wenden.
ndhvu275
Znuny advanced
Posts: 139
Joined: 06 Nov 2012, 09:02
Znuny Version: 3.x, 4.x and 5.x
Real Name: Vu Nguyen
Company: INFOdation
Location: Netherlands
Contact:

Re: Run the event of TicketStateUpdate only one time

Post by ndhvu275 »

tto wrote:
ndhvu275 wrote:
And my issue is how to prevent updating of state run in multi sub level in paren/child ticket. For example, there is a parent <- a child ticket <- a sub child ticket <- a sub sub child ticket, when update state of a sub sub child ticket, JUST ALLOW to update one level up for state of a sub child ticket. DO NOT allow to update state of a child ticket/ parent child.

Do you use "Transaction" in your event registration? I just had a similar situation where one event handler was supposed to trigger another one but it didn't. After changing the event configuration to Transaction=0 it did. I Haven'T had the time to find out the exact reason for this behavior - it might be related to some other core modifications. But you can give it a try, to set Transaction => 1.

Otherwise your event handler must check that the event is only performed if the ticket is a root-node in the ticket link-graph, so you should check that the ticket is parent, but no child to another ticket.

regards, T.
I didn't use "Transaction" yet, Your solution is really a good one for me, it's very useful and ofcourse I will try

Thank you so much

Vu Nguyen
OTRS 3.x, 4.x on CentOS/Windows
MySQL database
External customer backend with MySQL, MSSQL
Customization
Post Reply