Dynamicfield Update

Moderator: crythias

Post Reply
ritico
Znuny newbie
Posts: 21
Joined: 23 Apr 2010, 22:02
Znuny Version: 5s...
Real Name: Ramiro

Dynamicfield Update

Post by ritico »

Hi to everyone,

We are using OTRS 5s, and we need that when the state of a master ticket is changed, the value of a dynamic field that we have defined, will replicated in the slaves that have that master ticket related.

I added the following code in the file /opt/otrs/Kernel/System/Ticket/Event/MasterSlave.pm:


use Kernel::System::ObjectManager;
local $Kernel::OM = Kernel::System::ObjectManager->new();
my $DynamicFieldValueObject = $Kernel::OM->Get('Kernel::System::DynamicFieldValue');

# perform action on linked tickets
TICKETID:
for my $TicketID (@TicketIDs) {

my $CheckSuccess = $Self->_LoopCheck(

TicketID => $TicketID,
UserID => $Param{UserID},
String => 'MasterTicketAction: TicketDynamicFieldUpdate_Causa',
);

next TICKETID if !$CheckSuccess;

# get Causa dynamic field
my $CausaDynamicField = $ConfigObject->Get('Causa::DynamicField');

# set the value
$DynamicFieldValueObject->ValueSet(
FieldID => 8, #$FieldID,
ObjectID => $TicketID,

Value => [
{ ValueText => $Ticket{ 'DynamicField_' . $CausaDynamicField }, },
],

UserID => $Param{UserID},
);
}
return 1;
}


We did several tests, but we didn´t get the dynamic field was updated.
I would appreciate any help you can give us.
Thank you very much.

Regards,
Ramiro
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Dynamicfield Update

Post by RStraub »

Please put code into Code tags.

This is what I usually use in a loop:

Code: Select all

            my $CurFieldConfig = $DynamicFieldObject->DynamicFieldGet(
                ID   => $CurFieldID,
                Name => 'DynamicField',
            );
            $Success = $DynamicFieldBackendObject->ValueSet(
                DynamicFieldConfig => $CurFieldConfig,
                ObjectID       => $NewTicketID,
                Value          => $NewValue,
                UserID         => $Self->{UserID},
            );
and to initialize the objects:

Code: Select all

    my $DynamicFieldObject        = $Kernel::OM->Get('Kernel::System::DynamicField');
    my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
ritico
Znuny newbie
Posts: 21
Joined: 23 Apr 2010, 22:02
Znuny Version: 5s...
Real Name: Ramiro

Re: Dynamicfield Update

Post by ritico »

I tried the code you sent me but I still cannot get it to work.
We have OTRS version 5s.

The code said:

Code: Select all

my $CurFieldConfig = $DynamicFieldObject->DynamicFieldGet(
                ID   => $CurFieldID,
                Name => 'DynamicField', 
            );
#Don’t we have to put here the real name of the dynamic field in the Name variable?

And here:

Code: Select all

            $Success = $DynamicFieldBackendObject->ValueSet(
                DynamicFieldConfig => $CurFieldConfig,
                ObjectID       => $NewTicketID,
                Value          => $NewValue, #
                UserID         => $Self->{UserID},
            );
#Shouldn’t we use the following structure, depending on the data type we have defined?

like this:

Code: Select all

               Value    => [
                                 { 
                                   ValueText => 'Contenido',
                                 },
                               ],
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Dynamicfield Update

Post by RStraub »

Yes, you should provide the ID or the Name of the dynamic field, see here:
http://doc.otrs.com/doc/api/otrs/5.0/Pe ... ld.pm.html

The value will be matched automatically to value_text (or whatever) depending on the provided config, see here:
http://doc.otrs.com/doc/api/otrs/5.0/Pe ... nd.pm.html
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
ritico
Znuny newbie
Posts: 21
Joined: 23 Apr 2010, 22:02
Znuny Version: 5s...
Real Name: Ramiro

Re: Dynamicfield Update

Post by ritico »

Thank you very much Rolf!!
The information you sent us was very useful.
Now it works well!

Regards,
Ramiro
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Dynamicfield Update

Post by RStraub »

My pleasure, glad it works :)
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Post Reply