Updating value of dynamic fields

Moderator: crythias

Locked
msaeed
Znuny newbie
Posts: 6
Joined: 23 Jul 2013, 07:20
Znuny Version: 3.2.5
Real Name: Muhammad Imran Saeed

Updating value of dynamic fields

Post by msaeed »

Hello All,

I am facing a problem with dynamic field update. I have created a dynamic field and it is working fine with the initial(default value). When ticket is opened it has a default value but it is updated later on. Problem is value is updated in "ticket" table but it is not being reflected in :( in web.

OTRS version is 3.1.x

I used phpAdmin for updating values of dynamic field.

Any help in this regards will be highly appreciated.

Best Regards,

Muhammad Imran Saeed.
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Updating value of dynamic fields

Post by jojo »

Don't change things manualy in the database!

you need to delete the caches
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
msaeed
Znuny newbie
Posts: 6
Joined: 23 Jul 2013, 07:20
Znuny Version: 3.2.5
Real Name: Muhammad Imran Saeed

Re: Updating value of dynamic fields

Post by msaeed »

Thank you very much for the reply @JOJO.
Can you please tell me how can i delete cache for a particular ticket.

Is it possible to do it for particular ticket?
If not what will be its impact on performance of the system.

Actually i am working on a proof of concept. Right now i am doing it manually but later on it will be done automatically.

Will following script do the job for me :? ?
https://github.com/bieli/otrs-helpdesk- ... teCache.pl

Best Regards,
Muhammad Imran Saeed
Last edited by msaeed on 23 Jul 2013, 08:26, edited 1 time in total.
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Updating value of dynamic fields

Post by jojo »

on production systems you should never update database manually. Use the OTRS API or the webservices provided for this (as they will update the cache).

You can just delete all caches (/bin/otrs.DeleteCache.pl), so the system will be slower for a certain time as all caches need to be filled again.
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
msaeed
Znuny newbie
Posts: 6
Joined: 23 Jul 2013, 07:20
Znuny Version: 3.2.5
Real Name: Muhammad Imran Saeed

Re: Updating value of dynamic fields

Post by msaeed »

Thank you JOJO for your prompt reply.

Following is what I am trying to implement.

I have a web form that user will use for creating a ticket.User fills this form and submits through website. This form is sent as an email to the OTRS inbox which in turn creates a ticket. And on ticket table insert I was considering to write a trigger that will update/add values in dynamic fields. These values are submitted through form. Please note that form has some customer information and some dynamic fields. Please suggest is this approach correct or I should go for what you suggested in your previous post I should go for webservice or API. Which one will be more appropriate in given scenario.

I really appreciate your help.

Best Regards,
Muhammad Imran Saeed.
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Updating value of dynamic fields

Post by jojo »

The webservice would be the best approach
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
msaeed
Znuny newbie
Posts: 6
Joined: 23 Jul 2013, 07:20
Znuny Version: 3.2.5
Real Name: Muhammad Imran Saeed

Re: Updating value of dynamic fields

Post by msaeed »

@JOJO thank you very much for useful information.

Now can you please tell me if there is any JAVA based Webservice Client available for integration with OTRS. There is a lots of confusions for example /otrs//rpc.pl or /nph-genericinterface.pl should be use. Please tell me if there is some documentation for it ?

Thanks for the help.
Best Regards,
Muhammad Imran Saeed
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Updating value of dynamic fields

Post by jojo »

rpc.pl is direct API access, so the nph-genericinterface.pl is the better aproach.

You can find some documentations here: https://github.com/OTRS/otrs/tree/maste ... ebservices and here http://blog.otrs.org/2012/10/03/easy-ti ... interface/
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
msaeed
Znuny newbie
Posts: 6
Joined: 23 Jul 2013, 07:20
Znuny Version: 3.2.5
Real Name: Muhammad Imran Saeed

Re: Updating value of dynamic fields

Post by msaeed »

Thanks @ JOJO.

I have successfully executed a couple of webservices.
Above links helped a lot. I will share all my work in a blog.

Thanks once again for help.

This thread can be marker as SOLVED.
kishormali
Znuny newbie
Posts: 12
Joined: 20 Jan 2020, 12:12
Znuny Version: 6.0
Real Name: Kishor Mali

Re: Updating value of dynamic fields programmatically

Post by kishormali »

Hi Everyone,

I have to update DynamicField programatically.
I have an Invoker which called after "TicketCreate".
When control comes to HandleResponse method, I want to update DynamicField which is textarea with received response from Third Party webservice.

I tried as follows, but no luck.

Code: Select all

my $OperationObject    = $Kernel::OM->Get('Kernel::GenericInterface::Operation');
my %DynamicField = ('name'=> 'ContactLinks', 'value'=> 'Any Text Here');
	
$OperationObject->SetDynamicFieldValue(
	DynamicField => %DynamicField,
	TicketID  => $Param{Data}->{'TicketID'}
);
I can update Title, Status of Ticket but no luck with DynamicField yet. Any help is highly appreciated.
I took the reference of above code from \Kernel\GenericInterface\Operation\Ticket\TicketUpdate.pm file.
zzz
Znuny superhero
Posts: 914
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Updating value of dynamic fields

Post by zzz »

Hello,

Here is the API description of the function:

Code: Select all

    my $Result = $CommonObject->SetDynamicFieldValue(
        Name      => 'some name',           # the name of the dynamic field
        Value     => 'some value',          # String or Integer or DateTime format
        TicketID  => 123
        ArticleID => 123
        UserID    => 123,
    );
    my $Result = $CommonObject->SetDynamicFieldValue(
        Name   => 'some name',           # the name of the dynamic field
        Value => [
            'some value',
            'some other value',
        ],
        UserID => 123,
    );
    returns
    $Result = {
        Success => 1,                        # if everything is ok
    }
    $Result = {
        Success      => 0,
        ErrorMessage => 'Error description'
    }
Best regards
Emin
Professional Znuny and OTRS services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
kishormali
Znuny newbie
Posts: 12
Joined: 20 Jan 2020, 12:12
Znuny Version: 6.0
Real Name: Kishor Mali

Re: Updating value of dynamic fields

Post by kishormali »

Hi Emin,
Thanks a lot.

I have a query. Actually I am not a Perl developer, so it is difficult to understand.

What is $CommonObject? Where it comes from? I don't find anything like declaration with Class name.

If I will call it in \Kernel\GenericInterface\Invoker\Test\TestSugar.pm in here, will it work directly?

I want to update the value of DynamicField of the ticket when response came back from external webservice to HandleResponse method of Invoker.
zzz
Znuny superhero
Posts: 914
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Updating value of dynamic fields

Post by zzz »

Are you just trying to fill a dynamic field on ticket create via web service?
If so, you can do it while creating the ticket – API description.

You can also just use the direct API from everywhere within OTRS:

In this case, $DynamicFieldValueObject is $Kernel::OM->Get('Kernel::System::DynamicFieldValue')
and $CommonObject is $Kernel::OM->Get('Kernel::GenericInterface::Operation::Ticket::Common')

Best regards
Emin
Professional Znuny and OTRS services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
kishormali
Znuny newbie
Posts: 12
Joined: 20 Jan 2020, 12:12
Znuny Version: 6.0
Real Name: Kishor Mali

Re: Updating value of dynamic fields

Post by kishormali »

Hi Emin,
Thanks a lot again.

I think your current solution may complete my requirement.
Let me explain you the scenario.

I need to create same copy of OTRS ticket in SugarCRM.
When "TicketCreate" happen in OTRS, Invoker will call SugarCRM service and create a ticket in SugarCRM.
I want to return SugarCRM ticket record Id with reponse.
Consider the response came back with SugarTicketID.

Now, I have DynamicField in Ticket as ContactLinks - which must be updated with SugarURL/SugarTicketID. Whenever agent want to view ticket in SugarCRM, he can click on URL in OTRS and ticket will open in new tab.

Thanks a lot for help. I will let you know that the implementation is succeed or not.
kishormali
Znuny newbie
Posts: 12
Joined: 20 Jan 2020, 12:12
Znuny Version: 6.0
Real Name: Kishor Mali

Re: Updating value of dynamic fields

Post by kishormali »

Hi Emin,

You rock bro.
It worked like charm.

At first it gives following errors in otrs.log but later it works. The errors may be because the code may not reflect on save only.

Code: Select all

[Wed Feb  5 17:41:10 2020][Error][Kernel::GenericInterface::Invoker::new][102] Attempt to reload Kernel/GenericInterface/Invoker/Test/TestSugar.pm aborted.
Compilation failed in require at /opt/otrs//Kernel/System/Main.pm line 84.

[Wed Feb  5 17:41:10 2020][Error][Kernel::GenericInterface::Debugger::DebugLog][224] DebugLog error:  Summary: Can't load invoker backend module!  Data   : No data provided.
[Wed Feb  5 17:41:10 2020][Error][Kernel::GenericInterface::Debugger::DebugLog][224] DebugLog error:  Summary: InvokerObject could not be initialized  Data   : $VAR1 = {  'ErrorMessage' => 'Can\'t load invoker backend module!',  'Success' => 0};.
[Wed Feb  5 17:43:03 2020][Error][Kernel::GenericInterface::Invoker::new][102] Attempt to reload Kernel/GenericInterface/Invoker/Test/TestSugar.pm aborted.
Compilation failed in require at /opt/otrs//Kernel/System/Main.pm line 84.
Above error occurred whenever I changed something in Code. But after 2-3 trial it works properly.

Thanks a lot again!
zzz
Znuny superhero
Posts: 914
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Updating value of dynamic fields

Post by zzz »

You're welcome, Kishor =).
I am glad it worked.

After cleaning the cache and restarting the Apache, you should only get real errors.
su -c '/opt/otrs/bin/otrs.Console.pl Maint::Cache::Delete' -s /bin/bash otrs

Best regards
Emin
Professional Znuny and OTRS services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
Locked