Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Passing Value from FromAPIs to Perl script and bac
netsnaveen
Hi,
I am using FormAPIs and call an OnitemChange event. I need to use callserver and send parameters to perl script and also read the return variables. After I get that, I need to populate rows of textboxes.
If anybody has done, I would appreciate if U can share the samples. Also any other approach or suggestions.
Thanks,
Naveen.
Find more posts tagged with
Comments
Michael
Hi Naveen,
It sounds like you have got the right idea on how to do things. I have included some sample code off the top of my head below which might help you.
Firstly you register for your event:
IWEventRegistry.addItemHandler("/foo/bar", "onItemChange", fooBarChangeHandler);
In your handling function you perform your callServer
function fooBarChangeHandler(item) {
var params = new Object();
params.someParameterYouWishToPass = someValue;
IWDatacapture.callServer("/iw-bin/fooBarScript.ipl", params);
}
You have now passed control off to your perl script. In your perl script you perform whatever processing you need to perform and then by printing to STDOUT you can send JavaScript back to your form:
print <<EOT1;
<html>
<head>
<script language="javascript">
//alert("running script");
var api;
api = parent.getScriptFrame();
targetItem = api.IWDatacapture.getItem("/foo/bar");
// Populate the item with new values or some such
// Don't forget to redraw when you are done
api.IWDatacapture.redraw();
</script>
</head>
<body></body>
</html>
EOT1
You should also remember to add error handling for your callServer call -- tips on doing this are well documented in the manual.
Best approach is usually to attempt to get one piece working at a time -- eg make sure your onItemChange is firing using an alert; then make sure your callServer is working - perhaps by creating a log file and then get the output of the perl script working correctly.
I hope this helps and Good luck!
Cheers
Michael
netsnaveen
Hello,
I have been able to pass the value to perl script successfully. But am not able to get the value back in Javascript. Or rather even if the value is accessible in Javascript, probably print <<EOT1 till EOT1 is not working. Is there anything I should take care of here?
Please suggest.
Thanks,
Naveen.
A5_EPIL.zip
Michael
Hi Naveen,
Post up your ipl code and I'll take a look for you and see if I can suggest anything.
Cheers, Michael.
netsnaveen
HI Michael,
Pls find my ipl script and your help is appreciated.
#!/app/mass1/teamsite/iw-home/iw-perl/bin/iwperl
print "Content-type: text/html\n\n";
BEGIN
{
$ENV{'ORACLE_HOME'}="/master/ora817";
}
use DBI;
@Form1
= split(/&/,$ENV{'QUERY_STRING'});
$sdata="Naveen.dat";
open(DAT,">>$sdata") || die("Cannot Open File");
print DAT "Value passed is $ENV{'QUERY_STRING'} ";
close(DAT);
foreach $i (
@Form1)
{
($name, $value) = split(/=/,$i);
if ( $name == 'cCode')
{
$cCode = $value;
}
}
# use require command this to include any perl file where you can separately provide environment
$dbh=DBI->install_driver('Oracle') || die "sorry";
$dbh = DBI->connect('dbi
racle:ALL','dbusers','dbusers') || die "sorry could not connect";
$stm = "Select a.name, o.info, a.id, o.code from contacts o, branches a where o.code = $cCode and A.ID = O.CODE order by a.name";
$sth = $dbh->prepare("$stm");
$sth->execute;
my $str="";
while(
@row
= $sth->fetchrow_array())
{
print "<BR>";
print
@row
;
}
print "EOT";
print "<html>";
print "<head>";
print "<script language='javascript'>";
print "var api";
print "api = parent.getScriptFrame()";
print "</script>";
print "</head>";
print "<body>";
print "<input type=text name=abc />";
print "<table border=1> <tr> <td align='center'> Contacts </td> <td align='center'> Contact Info </td> </tr> </table>";
print "</body>";
print "</html>";
print "EOT";
# Logging to check if its being executed.
$sdata="Naveen.dat";
open(DAT,">>$sdata") || die("Cannot Open File");
print DAT "Value passed is $cCode ";
close(DAT);
# while (
@row
= $sth->fetchrow_array( ) ) {
# $str.="<option value=\"
@row[0]\"
label=\"
@row[1]\"/>
;\n";
# $str.="
@row[3]
@row[1]
\n";
# }
# print("<html> <title> Result of Query </title> <body> <input type=text name=MyButton "/> </body> </html>);
Thanks,
Naveen.
Michael
Hi Naveen,
You are close to what you want to do.
What you have to do is print JavaScript code out between your <script> tags which performs the formAPI calls you require. for example try adding the line print "api.alert(\"Hello world!\");" before your closing <script> tag.
Most likely you will want to have item.setValue() calls in here...
Hopefully this will give you the right idea of how to do this.
Cheers, Michael.