parameters in pm file

Moderator: crythias

Locked
tripti_rai2005
Znuny newbie
Posts: 67
Joined: 14 Mar 2012, 15:08
Znuny Version: OTRS2

parameters in pm file

Post by tripti_rai2005 »

in the following code..i am trying to post parameters inside %fields to a remote url..I am able to post the hard coded values..but i want to post the parameters..can you please tell me what am i doing wrong..in dtl files parameters are referred to as "$QData{"Subject"}".HOW to use them in pm file?

my %Fields = (
"Title" => $QData{"Subject"},
"Requester" => $QData{"Subject"},
"eMailr" => $QData{"Subject"} ,
"Description" => $QData{"Subject"},
);


sub SendValue {


my $URLtoPostTo = " http://engtech.whirlpool.com/etim-proje ... nhancement ";


my $BrowserName = "";


my $Browser = new LWP::UserAgent;

my $Page = $Browser->request(POST $URLtoPostTo,\%Fields);

# Print the returned page (or an error message).
print "Content-type: text/html\n\n";
if ($Page->is_success) { print $Page->content; }
else { print $Page->message; }

# end of script
■ TRIPTI RAI // PROJECT ENGINEER, ETIM GTEC
Office: +91 20 66056464 //Mobile: +91 9503019176 // // Whirlpool Corporation // www.WhirlpoolCorp.com
Whirlpool Corporation // www.WhirlpoolCorp.com
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: parameters in pm file

Post by reneeb »

*Please* use code-Tags when you post Code! Please post more details (what have you tried, what doesn't work, include error messages).

If the values are send via a webform you can use the ParamObject (methods GetParam/GetArray): http://dev.otrs.org/3.1/Kernel/System/Web/Request.html
If you want to use data stored in the DB you have to ask for them -- e.g. by using TicketObject, StateObject, ... (as you do not tell us any details we can't tell you more)
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
tripti_rai2005
Znuny newbie
Posts: 67
Joined: 14 Mar 2012, 15:08
Znuny Version: OTRS2

Re: parameters in pm file

Post by tripti_rai2005 »

Code: Select all

# get params
    my %GetParam;
    for (
        qw(
        From To Cc Bcc Subject Body 
        )
        )
    {
        $GetParam{$_} = $Self->{ParamObject}->GetParam( Param => $_ );
    }
   
my %Fields = (
   Subject => $GetParam{Subject},
   From => $GetParam{From},
   "eMailr" => "tripti_rai@whirlpool.com",
   "Description" => "test connection",
);

sub SendValue {


my $URLtoPostTo = " http://engtech.whirlpool.com/etim-projects-ecall/api/v1/Enhancement ";


my $BrowserName = "";


my $Browser = new LWP::UserAgent;

my $Page = $Browser->request(POST $URLtoPostTo,\%Fields);

# Print the returned page (or an error message).
print "Content-type: text/html\n\n";
if ($Page->is_success) { print $Page->content; }
else { print $Page->message; }

# end of script


In the above code as you mentioned, i am using getParam method to get the values.but it throws the following error
AgentTicketForward1.pm: Can't call method "GetParam" on an undefined value at D:/OTRS/OTRS//Kernel/Modules/AgentTicketForward1.pm line 467. Traceback (6040): Module: Kernel::System::Web::InterfaceAgent::Run (v1.58.2.1) Line: 188 Module: ModPerl::ROOT::ModPerl::Registry::D_3a_OTRS_OTRS_bin_cgi_2dbin_index_2epl::handler (unknown version) Line: 46 Module: (eval) (v1.89.2.1) Line: 204 Module: ModPerl::RegistryCooker::run (v1.89.2.1) Line: 204 Module: ModPerl::RegistryCooker::default_handler (v1.89.2.1) Line: 170 Module: ModPerl::Registry::handler (v1.99) Line: 31
Basically what i am trying to do is, pass these parameters named Subject, From, Body in "%fields" in the above code.Don't know how to get the value for all three in %fields to further use them in the code.
■ TRIPTI RAI // PROJECT ENGINEER, ETIM GTEC
Office: +91 20 66056464 //Mobile: +91 9503019176 // // Whirlpool Corporation // www.WhirlpoolCorp.com
Whirlpool Corporation // www.WhirlpoolCorp.com
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: parameters in pm file

Post by reneeb »

put

Code: Select all

# get params
    my %GetParam;
    for (
        qw(
        From To Cc Bcc Subject Body
        )
        )
    {
        $GetParam{$_} = $Self->{ParamObject}->GetParam( Param => $_ );
    }
   
my %Fields = (
   Subject => $GetParam{Subject},
   From => $GetParam{From},
   "eMailr" => "tripti_rai@whirlpool.com",
   "Description" => "test connection",
);
*inside* the subroutine SendValue

The module should have a proper constructor (subroutine new - see any Perl module at /<OTRS_HOME>/Kernel/System) where ParamObject etc. is required and checked
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
tripti_rai2005
Znuny newbie
Posts: 67
Joined: 14 Mar 2012, 15:08
Znuny Version: OTRS2

Re: parameters in pm file

Post by tripti_rai2005 »

thank you for the information!!!Now i am sucessfully able to retrieve values for following parameters .Correct code is:-

Code: Select all

my %CustomerData = $Self->{CustomerUserObject}->CustomerUserDataGet(User => $Ticket{CustomerUserID} );
my %Ticket = $Self->{TicketObject}->TicketGet( TicketID => $Self->{TicketID} ); 
my %Fields = (

   "Title" => $GetParam{Subject},
   "Requester" => $GetParam{From},
   "eMailr" => $GetParam{CustomerUserID},
   "Description" => $GetParam{Body},
   "Ecallnumber" => $Ticket{TicketNumber},
   "userid" => $Self->{UserID}
);

But i am facing a problem ..in $GetParam{From} instead of getting the email of requester, i am getting value as OTRS System <otrs@localhost>..How do i retrieve the actual value of from.
For your information i am doing all these changes in AgentTicketForward.pm one of the reasons why Value for From is OTRS System <otrs@localhost>.But i want the actual From value..i might be required to remove some piece of code i guess..could you direct me ?
■ TRIPTI RAI // PROJECT ENGINEER, ETIM GTEC
Office: +91 20 66056464 //Mobile: +91 9503019176 // // Whirlpool Corporation // www.WhirlpoolCorp.com
Whirlpool Corporation // www.WhirlpoolCorp.com
tripti_rai2005
Znuny newbie
Posts: 67
Joined: 14 Mar 2012, 15:08
Znuny Version: OTRS2

Re: parameters in pm file

Post by tripti_rai2005 »

Can some one please respond to my query
■ TRIPTI RAI // PROJECT ENGINEER, ETIM GTEC
Office: +91 20 66056464 //Mobile: +91 9503019176 // // Whirlpool Corporation // www.WhirlpoolCorp.com
Whirlpool Corporation // www.WhirlpoolCorp.com
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: parameters in pm file

Post by jojo »

Again read the developer Documentation or let some professional developer do the work for you
"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
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: parameters in pm file

Post by reneeb »

You already get all needed information. Have a look at http://dev.otrs.org/3.1/Kernel/System/CustomerUser.html
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
Locked