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)
Remote Server Calls
jamesk
When my dct loads i need to run 3 formapi callserver commands in succession. When the first one completes, it then triggers the second one to run and so on.
The problem is that the callserver method is asynchhronous. Which means i have to wait for the first call to finish to run the second otherwise it will cancel the first out.
Does anyone have any ideas on this - or ways to programatically trigger a script without user interaction.
thanks again
Find more posts tagged with
Comments
Adam Stoller
Just a thought - completely untested ...
Could you use hidden fields that the your callserver commands would change - and have an event handler for the hiddent fields so that when they change you call the next one (and so on, and so on) ?
--fish
(Interwoven Senior Technical Consultant)
jamesk
thanks for the response - i get the impression not many people out there are using formapi yet!
i also thought of doing this.
i set up a 'status' hidden text field. When the first callserver finishes it sets the value of the hidden field using .setValue().
The problem is that the event handler OnItemChange() doesnt trigger if you change the field using .setValue(), only if you change the text field yourself!
So i still have no way of knowing when my callserver has finished. There surely must be a way to do this.
thanks again
Migrateduser
I created a set of javascript functions to handle this. Basically, you use a series of calls to build a list of the callouts that need to be made. The information describing each server call is kept in a queue (really an Array()). A "completion" function is invoked by some javascript embedded in the results sent back by the server. The completion routine invokes the next server call in the queue.
Here's a somple of dct DCT script that drives all this:
<script><![CDATA[
var queue = new Array();
var queue_top;
/**<!----------------------------------------------------------------------->
* add_server_call -- add an HTTP call to the server to be processed on the server
*
* RETURNS
* Nothing.
*
* MODIFIES
* Adds entry to the queue.
*
* ARGUMENTS
* key (String) unique identifier of this call; usually the field name
* url (String) server URL
* params (Object) parameters passed to the server URL
* message (String) message displayed to the user when this entry is invoked
*
*<!----------------------------------------------------------------------->*/
function add_server_call( key, url, params, message ) {
var queue_entry = new Object();
queue_entry.key = key;
queue_entry.url = url;
queue_entry.params = params;
queue_entry.message = message;
queue[queue.length] = queue_entry;
}
/**<!----------------------------------------------------------------------->
* start_queue -- called to invoke the Nth entry in the queue
*
* RETURNS
* Nothing.
*
* MODIFIES
* starts Nth entry and sets queue_top to point to the Nth entry.
*
* ARGUMENTS
* n (Number) index of the entry to start
*
*<!----------------------------------------------------------------------->*/
function start_queue( n ) {
var queue_entry;
if (n < queue.length) {
queue_entry = queue;
top.hiddenFrameRunning = true;
IWDatacapture.displayMessage( queue_entry.message );
IWDatacapture.callServer( queue_entry.url, queue_entry.params );
queue_top = n;
}
else {
/* queue processing completed */
queue = new Array();
queue_top = 0;
}
}
/**<!----------------------------------------------------------------------->
* queue_entry_done -- called when processing is complete on the given queue_entry
*
* RETURNS
* Nothing.
*
* MODIFIES
* start next queue entry and increments queue_top.
*
* ARGUMENTS
* key (String) unique identifier of this call; usually the DCT item XPath
*
*<!----------------------------------------------------------------------->*/
function queue_entry_done( key ) {
var i;
for (i=0; i<queue.length; i++) {
if (queue
.key == key) {
IWDatacapture.displayMessage();
start_queue( i+1 );
}
}
}
function populate__n__region() {
var params = new Object();
params.value = "n_region";
params.label = "t_label";
params.table = "regions";
params.callback = "populate__n__region_callback";
var server = window.location.hostname;
add_server_call("/n_region", "http://"+server+":99/TeamSiteProvisional/PopulateSelection.aspx", params, "Loading /n_region..." );
}
function populate__n__region_callback(locations) {
//Clear the message display...
IWDatacapture.displayMessage();
var locationsItem = IWDatacapture.getItem("/n_region");
locationsItem.setOptions(locations);
IWDatacapture.redraw();
queue_entry_done( "/n_region" );
}
function populate__k__affiliate() {
var params = new Object();
params.table = "affiliates";
params.key = "/k_affiliate";
params.type = "int";
var server = window.location.hostname;
add_server_call("/k_affiliate","http://"+server+":99/TeamSiteProvisional/AssignKey.aspx", params, "Loading /k_affiliate..." );
}
populate__n__region();
populate__k__affiliate();
start_queue( 0 );
]]></script>
Migrateduser
Hi,
I am using the below statement before my callServer call.
IWDatacapture.displayMessage("Loading All ProductModels ...");
after my callServer call i am using this statement
IWDatacapture.displayMessage();
I am not seeing the message on DCR.
Could you pls. tell me where i am doing wrong
Thanx in advacne
JonathonG
Because callServer is asynchronous, you're two calls to displayMessage are executing one right after the other. To verify this, put a message in your second call, and you will see that one get displayed, but never the first one. To accomplish what you are trying to do, the second call to displayMessage needs to be located in the function that the callServer will make a callback to once it completes (assuming your CGI does a callback to the FormAPI. If not, there are several examples floating around these forums of how to do it.)
Jonathon
Interwoven Architecture Consultant
Migrateduser
Hi,
Did find any other way to knowing when callserver has finished?
Thanx in advance
JonathonG
Not sure what you're asking. When using the callServer method, everything that the CGI prints to STDOUT goes into a hidden frame on the DCT. From that frame you should be able to use parent.getScriptFrame() to get at the frame where your FormAPI is located. I recommend placing a function in your FormAPI code that you can call from this hidden frame. Thus, here are the pieces you need to get the callServer working properly:
1) In your FormAPI, create a function (in this example, called callback)
function callback()
{
alert("Called back from the callServer")
}
2) Elsewhere in your FormAPI, make a call to a CGI using callServer:
IWDatacapter.callServer("/iw-bin/myCGI.cgi");
3) In myCGI.cgi, print out the code that will call your callback function:
print <<EOF;
<HTML><HEAD><SCRIPT Language="javascript">
parent.getScriptFrame().callback();
EOF
That should get you round-tripped. For a more detailed example, see the "location" userscript example in iw-home/examples/Templating/templatedata/userscript/location
Jonathon
Interwoven Architecture Consultant
Migrateduser
Thanx for your reply.
My issues are like this
i>
In the below code i am using displayMessage() function
IWDatacapture.displayMessage("Pls.wait Saving DCR ...");
IWDatacapture.callServer('/iw-bin/Extranetdeploy.ipl',param,true);
IWDatacapture.displayMessage();
Actually before callServer executes ipl i want to display message then i want to clear msg after i finish callSerfunction. That is the reason i want synchronization between above statements.
2>
In below code i am sending param object . In my perl script based on input value it will result . I want to return that result to another variable after my callServer execution.
var result;
IWDatacapture.callServer('/iw-bin/Ex_WorkArea.ipl',param,true);
In this case i want to set the value for result in my callServer call.
Thanx in advance
JonathonG
For issue i>, simply remove the second "DisplayMessage" statement from where it is and put it in the callback (replacing the alert in my previous post).
For issue ii>, I'm not 100% sure what you're doing, but you could make the callback function take a parameter that is the new value and then set it there. Thus, when your cgi executes it would place into the javascript the value to be set.
Jonathon
Interwoven Architecture Consultant