Can't update DynamicFields with Perl API (TIcket::Update)

Moderator: crythias

Locked
JSouzaF
Znuny newbie
Posts: 10
Joined: 31 Jul 2015, 20:16
Znuny Version: OTRS 5.0.7
Company: UFJF

Can't update DynamicFields with Perl API (TIcket::Update)

Post by JSouzaF »

Hi,

I'm currently working on a custom module for OTRS and I'm trying to update some of the ticket's properties. For updating them, I've followed https://otrs.github.io/doc/api/otrs/6.0 ... te.pm.html

The only things I still could not change (for the ones I tried) are the dynamic fields.

The error message I get is "TicketUpdate.InvalidParameter: TicketUpdate: DynamicField->Name parameter is invalid!". I tried usiing both the name of the field "MyTestField" and it's composed form (retrieved from TicketGet) "DynamicField_MyTestField". Both return the same message. I don't really know what name I should look for but the one I gave.

Any tips?

Also, there's something else I'm wondering and will just ask about this "WebserviceID", what's really up to it? I can choose the ID or some of the IDs have specific meanings? Couldn't really find the answer by now..


Thanks in advance!

Code: Select all

    my $DebuggerObject = Kernel::GenericInterface::Debugger->new(
        DebuggerConfig   => {
            DebugThreshold => 'debug',
            TestMode       => 0,
        },
        WebserviceID      => 254,
        CommunicationType => 'Provider',
    );

    my $updateObj = Kernel::GenericInterface::Operation->new(
        DebuggerObject => $DebuggerObject,
        Operation      => 'TicketUpdate',
        OperationType  => 'Ticket::TicketUpdate',
        WebserviceID   => 254,
    );
    
    
    	my $Result = $updateObj->Run(
		Data => {
				SessionID => $Self->{SessionID},
				TicketNumber => XXXXXXXXXX',
				DynamicField => {
					Name => 'MyTestField',
					Value => "foo",
				},
				Ticket => {
					PriorityID => 2,
				},
			},
		);
		
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Can't update DynamicFields with Perl API (TIcket::Update)

Post by crythias »

Are you actively seeking Generic Interface or a "Custom Module"?
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
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Can't update DynamicFields with Perl API (TIcket::Update)

Post by RStraub »

From the 4.0 API it reads:

Code: Select all

           DynamicField => [                                                  # optional
               {
                   Name   => 'some name',
                   Value  => $Value,                                          # value type depends on the dynamic field
               },
               # ...
           ],
           # or
           # DynamicField {
           #    Name   => 'some name',
           #    Value  => $Value,
           #},
WIthout testing, it seems that you have to change either:
1) Add squared brackets around the hashes (to create an array)
2) OR remove the fat arrow behind DynamicField (though I'm weirded out by this, doesn't seem to be the correct way)
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
JSouzaF
Znuny newbie
Posts: 10
Joined: 31 Jul 2015, 20:16
Znuny Version: OTRS 5.0.7
Company: UFJF

Re: Can't update DynamicFields with Perl API (TIcket::Update)

Post by JSouzaF »

RStraub:
I've tried both of them.. If I don't use the arrow, I get an error as you expected (doesn't seem right) -> "Can't locate object method "DynamicField" via package "Name" (perhaps you forgot to load "Name"?)"
If I use square brackets, the results is the same I mentioned on my original post saying the name is invalid.

crythias:
It's actually a generic interface. For now, I'm trying out the basics of ticket manipulation thought the API and can't get to change the DynamicFields' values I'll be using.. The other properties I can change just fine..
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Can't update DynamicFields with Perl API (TIcket::Update)

Post by RStraub »

So, just to make sure, you used this format ? (because your example shows otherwise)

Code: Select all

    my $Result = $updateObj->Run(
        Data => {
            SessionID => $Self->{SessionID},
            TicketNumber => XXXXXXXXXX',
            DynamicField => [
               {
                   Name => 'MyTestField',
                   Value => "foo",
                },
            ],
            Ticket => {
               PriorityID => 2,
            },
         },
    );
I took a look into the module and the error you're describing is thrown if the structure is not:

Code: Select all

[ (Array-Ref)
    { (Hash-Ref)
        DATA
   },
],
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
JSouzaF
Znuny newbie
Posts: 10
Joined: 31 Jul 2015, 20:16
Znuny Version: OTRS 5.0.7
Company: UFJF

Re: Can't update DynamicFields with Perl API (TIcket::Update)

Post by JSouzaF »

Yes, I've uset this now again to make sure

Code: Select all

    	my $Result = $updateObj->Run(
		Data => {
				SessionID => $Self->{SessionID},
				TicketNumber => XXXXXXXXXX',
				DynamicField => [
					{
						Name => 'MyTestField',
						Value => "foo",
					},
				],
				Ticket => {
					PriorityID => 2,
				},
			},
		);
and the error is still: TicketUpdate.InvalidParameter: TicketUpdate: DynamicField->Name parameter is invalid!
Locked