Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
returning varialbe to formapi script from cgi
kellyrmilligan
I am using call server to determine a file size.
here is the javascript portion:
function getSize(item){
if ( IWDatacapture.getItem( "/PDFLinkContainer/PDFLinkReplicant" ).getChildren() != null )
{
for( i = 0 ; i < IWDatacapture.getItem( "/PDFLinkContainer/PDFLinkReplicant" ).getChildren().length ; i++ )
{
var index = i + 1;
// do something with "/Data/Sections[" + index + "]/SectionBody";
var path = IWDatacapture.getItem("/PDFLinkContainer/PDFLinkReplicant[" + index + "]/File_Name").getValue();
path = "/iwmnt/default/main/BCBSTX/Providers/WORKAREA/Content" + path;
//alert("The path going in is " + path);
var params = new Object();
params.path = path;
IWDatacapture.displayMessage("Determining file sizes ...");
top.hiddenFrameRunning = true;
var server = window.location.hostname;
IWDatacapture.callServer("http://"+server+"/iw-bin/file_size.cgi", params);
}
}
} //endfunction
I then want to return this value(size of file) to the javascript in a separate function:
function receiveCgi(cgisize){
IWDatacapture.displayMessage();
IWDatacapture.redraw();
alert(cgisize);
}//end f
This is just for testing, I will eventually set the value of another field. The perl code below is used to send the value back to the js
print <<EOT;
<html>
<head>
<script language="javascript">
var size = $cgisize;
alert(size);
</script>
</head>
<body onload='parent.getScriptFrame().receiveCgi("size")'>
</body>
</html>
EOT
close LOG;
exit;
I am not getting any thing in the dcr in the form of an alert or anything. any ideas?
Kelly
Find more posts tagged with
Comments
Migrateduser
I am not sure if the code on this post is the complete listing or an excerpt. I will assume that it is the complete listing.
There are several things you can check.
1. Is the formapi enabled?
2. Is getSize() getting called?
3. Is your CGI getting hit?
4. Is your CGI response well-formed HTTP?
For item 1, just make sure you have the following in your iw.cfg file:
[teamsite_templating]
enable_formapi=true
For item 2, make sure getSize() is either registered to handle an event on the form, or is called by a handler...
To check for item 3, you can either look at your webserver logs (in this case, the log files under $IWHOME/iw-webd/logs). You might also want to alert the URL you are passing into callServer() and try hitting that URL manually in a browser to see if it responds.
The above also tests for Item 4. I did notice, however, that you are missing the Content-type header information in your CGI response. You might want to add something like:
print "Content-type: text/html\n\n";
if it isn't there already.
--Daniel
kellyrmilligan
1. yes, formapi is enabled
2. getSize is getting called
3. the cgi is getting hit, I am logging the variable values.
4. I think it is, I will hit it directly through the browser to see if that gets me anything. I had this problem last time I did this, and the code is nearly identical. The main problem is that receivecgi is not being executed.
Migrateduser
Hi did you get your stuff resolved ..?
i need some kind of similar stuff to be done ...
what's your response by the way ..?
thanks
kellyrmilligan
Here is the jist of the code, I passed my cgi a variable, in this case a path to a file, and got the size of the file back.
function getSize2(item){
var xpath = item.getName();
var path = IWDatacapture.getItem(xpath).getValue();
path = "/iwmnt/default/main/BCBSIL/Producer/WORKAREA/Content" + path;
var myIndex = xpath.split('[');
var myIndex2 = myIndex[1].split(']');
//alert(myIndex2[0]);
var index = myIndex2[0];
var xpathsize = "/PDFLinkContainer/PDFLinkReplicant[" + index + "]/fileSize";
//alert(xpathsize);
var params = new Object();
params.xpathsize = xpathsize;
params.path = path;
IWDatacapture.displayMessage("Determining file sizes ...");
top.hiddenFrameRunning = true;
var server = window.location.hostname;
IWDatacapture.callServer("http://"+server+"/iw-bin/file_size.cgi", params);
} //endfunction
function receiveCgi(cgisize, xpathsize){
//alert("Here is the stuff " + cgisize + " " + xpathsize);
IWDatacapture.displayMessage();
IWDatacapture.redraw();
var path = IWDatacapture.getItem(xpathsize).setValue(cgisize);
IWDatacapture.getItem(xpathsize).setReadOnly(true);
}//end function
This is the last part of my cgi that gives the response:
## Note that an initial empty line is required.
print <<EOT;
<html>
<head>
<script language="javascript">
</script>
</head>
<body onload='parent.getScriptFrame().receiveCgi("$cgisize", "$xpathsize")'>
</body>
</html>
EOT
it calls the receivecgi function, so that you can do whatever else you want with the variable.
Hope this helps.
Kelly
Migrateduser
Excellent
many thanks
take care
Kyocera3.drs
Kyocera3_opt.txt
platform.dua
Migrateduser
why did you harcode the path ..?
try var area = parent.gTDT;...can be helpful
take care
Migrateduser
are u sure this piece of code works ..?
print <<EOT;
<html>
<head>
<script language="javascript">
</script>
</head>
<body onload='parent.getScriptFrame().receiveCgi("$cgisize", "$xpathsize")'>
</body>
</html>
EOT
no print "Content-type: text/html\n\n";
before ..?
your kind of code duno work for me ...
thks
Capture.JPG
kellyrmilligan
yes, I am sure it works. you do have to make sure that there needs to be an empty line after the print <<EOT; statement, that was **** mine up forever. also, mine is located in /usr/iw-home/httpd/iw-bin/ and is a cgi script, so trying just typing in the correct url to see if you get any errors, it should be able to execute via the web server.
hope this helps,
Kelly
5026.doc
Migrateduser
well duno understand can't get the answer my cgi is called but the the return method doesn't get the answer :
use CGI;
use LockFile::FMutex;
#Turn buffering off.
$| = 1;
my $in = new CGI;
my $catype = $in->param('area');
# we should be able to choose one file according the category/type : To be modified
my $id_file = '/data/software/iw/iw-home/local/config/bt-btw-u/Id/product.id';
my $logfile = '/data/software/iw/iw-home/tmp/upc/log/testmutex.log';
my $returnId;
open (LOGFILE, "> $logfile") or
die "Cannot open $logfile: $!";
print LOGFILE " got called \n";
lock_and_do_restricted();
#printReturn();
sub lock_and_do_restricted {
print LOGFILE "****************** entered lock_and_do_restricted()\n********************";
my $lock = new FMutex(
-MutexPath => '/data/software/iw/iw-home/tmp/file.lck',
-WaitTime => 30,
-OpenLocked => 1
);
unless ($lock) {
print FMutex::ErrorMessage(), "\n";
return;
}
print LOGFILE "******************before call to update_id()\n\n********************";
update_id();
print LOGFILE "******************after call to update_id()\n\n*********************";
}
sub update_id {
print LOGFILE "****************** entered update_id()\n\n********************";
my $id = 0;
if(isExistIdFile($id_file)){
print LOGFILE "******************file : $id_file already exist\n\n********************";
open (ID_FILE, "$id_file") or
die "Cannot open $id_file: $!";
my
@id_array
= <ID_FILE>;
$id = $id_array[0];
close(ID_FILE);
open (ID_FILE, "> $id_file") or
die "Cannot open $id_file: $!";
seek(ID_FILE, 0,0);
$id++;
print ID_FILE $id;
#print "id after: $id\n";
close(ID_FILE);
}else{
open (ID_FILE, "> $id_file") or
die "Cannot open $id_file: $!";
$id=0;
print print ID_FILE $id;
close(ID_FILE);
`chmod 777 $id_file`;
}
$returnId = $id;
print LOGFILE "Value of returnID: $returnId\n\n";
}
sub isExistIdFile {
if(-f $id_file) {return 1};
return 0;
}
print <<EOT;
<html>
<head>
<script language="javascript">
</script>
</head>
<body onload='parent.getScriptFrame().receiveCgi("$returnId")'>
</body>
</html>
EOT
close(LOGFILE);
don't understand
Migrateduser
you are right it's working i apologize !!
thanks
kellyrmilligan
so was there anything wrong with the code that you put up there?
Kelly
Edited by kellyrmilligan on 06/13/03 10:40 AM (server time).
vahu
Hi, I am trying some of the same stuff. My second (setUserInfo) functions get called,
but I am trying to pass a string to the function that I extract in the .ipl script. The value passed is always empty or a # sign.
The email_map.cfg has been modified so that it has entries like the following : domain/username :
email@email.com
#Full user name eg. Don Joe
Can someone quickly, easily spot the error ?
<script><![CDATA[
getUserInfo();
function getUserInfo(){
var userDomainAndName = IWDatacapture.getUser();
var regEx = /\\/g;
//escaping the single back slash
var userDomainAndName = userDomainAndName.replace(regEx, "\\\\");
alert(userDomainAndName );
parameters = new Object();
parameters.userName = userDomainAndName;
IWDatacapture.displayMessage("Getting mail address ...");
top.hiddenFrameRunning = true;
IWDatacapture.callServer("/iw-bin/NNIT_SCRIPTS/nnit_GetUserFullnameAndMail.ipl");
}
function setUserInfo(userEmailAdd){
IWDatacapture.displayMessage();
IWDatacapture.redraw();
//alert(fullUserName);
alert(userEmailAdd);
}
]]>
</script>
#!d:/iw-home/iw-perl/bin/iwperl
use CGI;
use Teamsite::Config;
use lib "/iw_home/httpd/iw_bin/NNIT_SCRIPTS";
use nnit_Functions;
my${cgi} = new CGI();
my $userDomainAndName = ${cgi}->param('userName');
my $userEmailAdd = "";
my $fullUserName = "";
my $returnString = "";
my $iwHome = nnit_getconfig("locations", "iwhome");
my $emailConfigPath = $iwHome . "/local/config/wft/email_map.cfg";
open MYFILE, "<" . $emailConfigPath
or die "Fejl i læsning af email_map.cfg filen";
while ($linie = <MYFILE>) {
chomp ($linie);
if($linie =~ /^$userDomainAndName/){
$linie =~ s/$userDomainAndName//g;
$returnString = $linie;
last;
}
}
close MYFILE;
print <<"EOT";
<html>
<head>
<script language="javascript">
alert("vahu");
</script>
</head>
<body onload='parent.getScriptFrame().setUserInfo("$returnString")'>
</body>
</html>
EOT
exit 0;
Adam Stoller
It's a bit unclear in your post where the problem is occurring. Does the alert() in the javascript code show the correct value? Can you add more debugging to your Perl code to see what value is being retrieved?
--fish
(Interwoven Senior Technical Consultant)
vahu
Hi fish,
Well I have attached word doc that might help clarify things. If I execute the script from a cmd prompt then the HTML that gets printed tp the cmd window looks correct (see the doc). Meaning that the $returnString has been substitutet by the extracted line. But when I try the same things from the TeamSite DCR then the alert just shows "#" (see doc). The funny thing as I wrote in my previous posting, that if I hardcode $returnString then it get parsed correctly. Hope this help clarify the issue. A quick response would be highly appreciated, since we ar going 'live' tomorrow. Remember to rename the file from .zip to .doc
Adam Stoller
Unfortunately: (a) I had a project consuming all my time that had to be ready for today too, and (b) I do not seem to be able to open your attached document - so I'm afraid I cannot provide much help here for you.
As I will be largely out of communication for the rest of this week and next, hopefully someone else will be able to assist you here.
In general, I'd suggest trying to step through your code line by line and if possible, get someone else (a "fresh pair of eyes") to look it over too.
--fish
(Interwoven Senior Technical Consultant)