Is it possible we can send dynamic field values via SOAP RPC?

Moderator: crythias

Post Reply
sunny
Znuny newbie
Posts: 68
Joined: 30 Aug 2011, 13:14
Znuny Version: 5.0.22
Real Name: Sunny
Contact:

Is it possible we can send dynamic field values via SOAP RPC?

Post by sunny »

Is it possible we can send dynamic field values via SOAP RPC in PHP?

I have added a new dynamic field ticket type and would like to send those value from rpc.pl (php)

I am using 5.0.4
root
Administrator
Posts: 3934
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Is it possible we can send dynamic field values via SOAP RPC?

Post by root »

Hi,

This will work but I recommend using the GenericInterface with REST or SOAP (whatever your prefer).
An example client is available on my github repo https://github.com/rkaldung/otrs-gi-rest-php

- 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 ?
sunny
Znuny newbie
Posts: 68
Joined: 30 Aug 2011, 13:14
Znuny Version: 5.0.22
Real Name: Sunny
Contact:

Re: Is it possible we can send dynamic field values via SOAP RPC?

Post by sunny »

Thanks, I have used GenericInterface with SOAP but unable to pass the dynamic ticket field value

I have created the DF like below
Capture.JPG
and added to the agent ticket zoom sceen
sysconfig-dynamic.jpg
and now want to send its value via the bin/otrs.SOAPRequest.pl, please help..
You do not have the required permissions to view the files attached to this post.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Is it possible we can send dynamic field values via SOAP RPC?

Post by reneeb »

Did you try this XML?

Code: Select all

my $XMLData = '
<UserLogin>some user login</UserLogin>
<Password>some password</Password>
<Ticket>
    <Title>some title</Title>
    <CustomerUser>some customer user login</CustomerUser>
    <Queue>some queue</Queue>
    <State>some state</State>
    <Priority>some priority</Priority>
</Ticket>
<Article>
    <Subject>some subject</Subject>
    <Body>some body</Body>
    <ContentType>text/plain; charset=utf8</ContentType>
</Article>
<DynamicField>
  <Name>MyName</Name>
  <Value>Something you want to send</Value>
</DynamicField>
';
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
sunny
Znuny newbie
Posts: 68
Joined: 30 Aug 2011, 13:14
Znuny Version: 5.0.22
Real Name: Sunny
Contact:

Re: Is it possible we can send dynamic field values via SOAP RPC?

Post by sunny »

Hi Reneeb,

Thanks it is working via XML but our third party software is in PHP from where we want to send details to OTRS.

So any idea how to do with PHP? because given solution was implemented in perl.


Help would be appreciated.
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Is it possible we can send dynamic field values via SOAP RPC?

Post by jojo »

A PHP developer should be able to understand and read the PERL code. (Please don't do copy and paste deveoplement...)
"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
sunny
Znuny newbie
Posts: 68
Joined: 30 Aug 2011, 13:14
Znuny Version: 5.0.22
Real Name: Sunny
Contact:

Re: Is it possible we can send dynamic field values via SOAP RPC?

Post by sunny »

Actually we are doing with PHP and it is already working but my original problem remains same that we are not able to pass the dynamic field ticket value to OTRS from our third party PHP application.

but anyways thanks for your great help..
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Is it possible we can send dynamic field values via SOAP RPC?

Post by reneeb »

If you have a working PHP sample, what's the problem? You should know how the data has to be created in the PHP script. If you are not allowed to change the third party PHP application, you should contact its vendor. We do not know the third party software, so it is hard for us to give any hints...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
sunny
Znuny newbie
Posts: 68
Joined: 30 Aug 2011, 13:14
Znuny Version: 5.0.22
Real Name: Sunny
Contact:

Re: Is it possible we can send dynamic field values via SOAP RPC?

Post by sunny »

Below is my PHP code

Want to send Source as a dynamic field ==> "Source","MyCUSTOMWEBAPP",

I tried this way too -> <OTRS_TICKET_DynamicField_Source_Value>

I am using OTRS 5.0.9

Code: Select all

# creating a ticket number

            $ticketnr = $client->__soapCall("Dispatch",
                array($username, $password, "TicketObject", "TicketCreateNumber"));
            if(! is_string($ticketnr) )
                echo $ticketnr = number_format($ticketnr,0, '.', '');

            $TicketID= $client->__soapCall("Dispatch",
                array($username, $password,
                    "TicketObject", "TicketCreate",
                    "TN", $ticketnr,
                    "Title", $title,
                 "Source","MyCUSTOMWEBAPP",
                    "Queue", "Raw",
                    "Lock" , "unlock",
                    "PriorityID", 3,
                    "State" , "new",
                    "CustomerID", $from,
                    "CustomerUser", $from,
                    "OwnerID",     1,
                    "UserID", 1
                ));

			$ArticleID = $client->__soapCall("Dispatch",
            array($username, $password,
                "TicketObject",     "ArticleSend",
                "TicketID",         $TicketID,
                "ArticleType",      "email-external",
                "SenderType",       "customer",
                "From",             $from,
                "To",             $email1,
                "Subject"          ,  '[Ticket#'.$ticketnr.'] '.$title,
                "ContentType"      , "text/plain; charset=utf-8",
                "Charset"           ,'utf-8',
                "HistoryType"      , "EmailCustomer",
                "HistoryComment"   , "generated by ",
                "Body"             , $body,
                "UserID"         	, 1,
                "NoAgentNotify"    , 0,
                "MimeType"         , "text/html",
                "Loop"             , 0
            )
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Is it possible we can send dynamic field values via SOAP RPC?

Post by reneeb »

The PHP code you've shown is for the old rpc.pl not for the GenericInterface... The old GenericInterface doesn't provide a way to set dynamic field values. You need to either switch to GenericInterface or change the rpc.pl
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
sameer615
Znuny newbie
Posts: 38
Joined: 16 Aug 2017, 11:26
Znuny Version: OTRS 5
Real Name: sameer sardar
Company: ENS

Re: Is it possible we can send dynamic field values via SOAP RPC?

Post by sameer615 »

add two lines in rpc.pl
$CommonObject{DynamicField} = $Kernel::OM->Get('Kernel::System::DynamicField');
$CommonObject{TicketDynamicObject}=$Kernel::OM->Get('Kernel::System::DynamicFieldValue');


Find Commented line #ADD THESE TWO LINE TO DEFINE DYNAMIC FIELD in rpc.pl

rpc.pl is given below

Code: Select all

#!/usr/bin/perl
# --
# Copyright (C) 2001-2016 xxx, http://otrs.com/
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU AFFERO General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
# or see http://www.gnu.org/licenses/agpl.txt.
# --

use strict;
use warnings;

# use ../../ as lib location
use FindBin qw($Bin);
use lib "$Bin/../..";
use lib "$Bin/../../Kernel/cpan-lib";
use lib "$Bin/../../Custom";

use SOAP::Transport::HTTP;
use Kernel::System::ObjectManager;
use Kernel::System::DynamicFieldValue;

SOAP::Transport::HTTP::CGI->dispatch_to('Core')->handle();

package Core;

sub new {
    my $Self = shift;

    my $Class = ref($Self) || $Self;
    bless {} => $Class;

    return $Self;
}

sub Dispatch {
    my ( $Self, $User, $Pw, $Object, $Method, %Param ) = @_;

    $User ||= '';
    $Pw   ||= '';
    local $Kernel::OM = Kernel::System::ObjectManager->new(
        'Kernel::System::Log' => {
            LogPrefix => 'OTRS-RPC',
        },
    );

    my %CommonObject;

    $CommonObject{ConfigObject}          = $Kernel::OM->Get('Kernel::Config');
    $CommonObject{CustomerCompanyObject} = $Kernel::OM->Get('Kernel::System::CustomerCompany');
    $CommonObject{CustomerUserObject}    = $Kernel::OM->Get('Kernel::System::CustomerUser');
    $CommonObject{EncodeObject}          = $Kernel::OM->Get('Kernel::System::Encode');
    $CommonObject{GroupObject}           = $Kernel::OM->Get('Kernel::System::Group');
    $CommonObject{LinkObject}            = $Kernel::OM->Get('Kernel::System::LinkObject');
    $CommonObject{LogObject}             = $Kernel::OM->Get('Kernel::System::Log');
    $CommonObject{MainObject}            = $Kernel::OM->Get('Kernel::System::Main');
    $CommonObject{PIDObject}             = $Kernel::OM->Get('Kernel::System::PID');
    $CommonObject{QueueObject}           = $Kernel::OM->Get('Kernel::System::Queue');
    $CommonObject{SessionObject}         = $Kernel::OM->Get('Kernel::System::AuthSession');
    $CommonObject{TicketObject}          = $Kernel::OM->Get('Kernel::System::Ticket');
    $CommonObject{TimeObject}            = $Kernel::OM->Get('Kernel::System::Time');
    $CommonObject{UserObject}            = $Kernel::OM->Get('Kernel::System::User');

    #ADD THESE TWO LINE TO DEFINE DYNAMIC FIELD
        $CommonObject{DynamicField} = $Kernel::OM->Get('Kernel::System::DynamicField');
        $CommonObject{TicketDynamicObject}=$Kernel::OM->Get('Kernel::System::DynamicFieldValue');

    my $RequiredUser     = $CommonObject{ConfigObject}->Get('SOAP::User');
    my $RequiredPassword = $CommonObject{ConfigObject}->Get('SOAP::Password');

    if (
        !defined $RequiredUser
        || !length $RequiredUser
        || !defined $RequiredPassword || !length $RequiredPassword
        )
    {
        $CommonObject{LogObject}->Log(
            Priority => 'notice',
            Message  => "SOAP::User or SOAP::Password is empty, SOAP access denied!",
        );
        return;
    }

    if ( $User ne $RequiredUser || $Pw ne $RequiredPassword ) {
        $CommonObject{LogObject}->Log(
            Priority => 'notice',
            Message  => "Auth for user $User (pw $Pw) failed!",
        );
        return;
    }

    if ( !$CommonObject{$Object} ) {
        $CommonObject{LogObject}->Log(
            Priority => 'error',
            Message  => "No such Object $Object!",
        );
        return "No such Object $Object!";
    }

    return $CommonObject{$Object}->$Method(%Param);
}

=item DispatchMultipleTicketMethods()

to dispatch multiple ticket methods and get the TicketID

    my $TicketID = $RPC->DispatchMultipleTicketMethods(
        $SOAP_User,
        $SOAP_Pass,
        'TicketObject',
        [ { Method => 'TicketCreate', Parameter => \%TicketData }, { Method => 'ArticleCreate', Parameter => \%ArticleData } ],
    );

=cut

sub DispatchMultipleTicketMethods {
    my ( $Self, $User, $Pw, $Object, $MethodParamArrayRef ) = @_;

    $User ||= '';
    $Pw   ||= '';

    # common objects
    local $Kernel::OM = Kernel::System::ObjectManager->new(
        'Kernel::System::Log' => {
            LogPrefix => 'OTRS-RPC',
        },
    );

    my %CommonObject;

    $CommonObject{ConfigObject}          = $Kernel::OM->Get('Kernel::Config');
    $CommonObject{CustomerCompanyObject} = $Kernel::OM->Get('Kernel::System::CustomerCompany');
    $CommonObject{CustomerUserObject}    = $Kernel::OM->Get('Kernel::System::CustomerUser');
    $CommonObject{EncodeObject}          = $Kernel::OM->Get('Kernel::System::Encode');
    $CommonObject{GroupObject}           = $Kernel::OM->Get('Kernel::System::Group');
    $CommonObject{LinkObject}            = $Kernel::OM->Get('Kernel::System::LinkObject');
    $CommonObject{LogObject}             = $Kernel::OM->Get('Kernel::System::Log');
    $CommonObject{MainObject}            = $Kernel::OM->Get('Kernel::System::Main');
    $CommonObject{PIDObject}             = $Kernel::OM->Get('Kernel::System::PID');
    $CommonObject{QueueObject}           = $Kernel::OM->Get('Kernel::System::Queue');
    $CommonObject{SessionObject}         = $Kernel::OM->Get('Kernel::System::AuthSession');
    $CommonObject{TicketObject}          = $Kernel::OM->Get('Kernel::System::Ticket');
    $CommonObject{TimeObject}            = $Kernel::OM->Get('Kernel::System::Time');
    $CommonObject{UserObject}            = $Kernel::OM->Get('Kernel::System::User');

    my $RequiredUser     = $CommonObject{ConfigObject}->Get('SOAP::User');
    my $RequiredPassword = $CommonObject{ConfigObject}->Get('SOAP::Password');

    if (
        !defined $RequiredUser
        || !length $RequiredUser
        || !defined $RequiredPassword || !length $RequiredPassword
        )
    {
        $CommonObject{LogObject}->Log(
            Priority => 'notice',
            Message  => "SOAP::User or SOAP::Password is empty, SOAP access denied!",
        );
        return;
    }

    if ( $User ne $RequiredUser || $Pw ne $RequiredPassword ) {
        $CommonObject{LogObject}->Log(
            Priority => 'notice',
            Message  => "Auth for user $User (pw $Pw) failed!",
        );
        return;
    }

    if ( !$CommonObject{$Object} ) {
        $CommonObject{LogObject}->Log(
            Priority => 'error',
            Message  => "No such Object $Object!",
        );
        return "No such Object $Object!";
    }

    my $TicketID;
    my $Counter;

    for my $MethodParamEntry ( @{$MethodParamArrayRef} ) {

        my $Method    = $MethodParamEntry->{Method};
        my %Parameter = %{ $MethodParamEntry->{Parameter} };

        # push ticket id to params if there is no ticket id
        if ( !$Parameter{TicketID} && $TicketID ) {
            $Parameter{TicketID} = $TicketID;
        }

        my $ReturnValue = $CommonObject{$Object}->$Method(%Parameter);

        # remember ticket id if method was TicketCreate
        if ( !$Counter && $Object eq 'TicketObject' && $Method eq 'TicketCreate' ) {
            $TicketID = $ReturnValue;
        }

        $Counter++;
    }

    return $TicketID;
};
now use below code to generate ticket along with dynamic fields

Code: Select all

 $ticketnr = $client->__soapCall("Dispatch",
                array($username, $password, "TicketObject", "TicketCreateNumber"));
            if(! is_string($ticketnr) )
                echo $ticketnr = number_format($ticketnr,0, '.', '');

            $TicketID= $client->__soapCall("Dispatch",
                array($username, $password,
                    "TicketObject", "TicketCreate",
                    "TN", $ticketnr,
                    "Title", $title,
                    "Queue", "Raw",
                    "Lock" , "unlock",
                    "PriorityID", 3,
                    "State" , "new",
                    "CustomerID", $from,
                    "CustomerUser", $from,
                    "OwnerID",     1,
                    "UserID", 1
                ));
            $dynfield = $client->__soapCall("Dispatch", array($username, $password,
                "DynamicField", "DynamicFieldGet",
                "Name", 'your_Dynamic_field_name'));
            $result = $client->__soapCall("Dispatch", array($username, $password,
                "TicketDynamicObject", "ValueSet",
                "FieldID", $dynfield->ID,
                "ObjectID", $TicketID,
                "Value", array("0" => array("ValueText" => 'Your_value')),
                "UserID", 1,
            ));

			$ArticleID = $client->__soapCall("Dispatch",
            array($username, $password,
                "TicketObject",     "ArticleSend",
                "TicketID",         $TicketID,
                "ArticleType",      "email-external",
                "SenderType",       "customer",
                "From",             $from,
                "To",             $email1,
                "Subject"          ,  '[Ticket#'.$ticketnr.'] '.$title,
                "ContentType"      , "text/plain; charset=utf-8",
                "Charset"           ,'utf-8',
                "HistoryType"      , "EmailCustomer",
                "HistoryComment"   , "generated by OTRS",
                "Body"             , $body,
                "UserID"         	, 1,
                "NoAgentNotify"    , 0,
                "MimeType"         , "text/html",
                "Loop"             , 0
            )
        );

It'll work for sure ...
Post Reply