Blog Entry
From time to time there are situations where you need a right-click operation to bounce back and forth between running on the server and running on the client workstation. Suppose you need to prompt the user for some information prior to opening a ticket, or sending an email, etc, but while the user needs to be prompted (run on the client side), the actual execution of the sending of an email or opening of the ticket needs to occur at the server (server side script) due to some technical limitation. There are some other cases where you need to use a specific Operation Center method that is only available on the client and/or server, but the core script you are doing is the opposite of what you need. Within this blog I will cover the basics of bouncing back and forth between a client script and a server script within an Operations Center right-click operation.
The first part is that the right-click operation must be defined as a serverscript. I’d go through all the 1’s and 0’s of why this is so, but I can only tell you that this is the way it works
The core features of the serverscript is to set up one or more functions for the clientscript to call (if needed) and then to kick off the client script similiar to how it is shown below.
session.invokeScript( "Client Side Script", "load( 'helloworldclient.fs' ); ", vals, flds );
The line above is the way to have a serverscript kick off a script on the client side. The first parm is the name, it’s not really needed. The next part is java script, typically a load statement to load a script. The next two are the variables and values that you want pre-created in the clientscript (similar to ‘element’ being predefined in an element operation).
The next section is the way to define functions that the client will be able to call. These functions when they are called from the client script, they are executed in the context of the server. For the example below they are hard coded to just return a string, parms could be passed in and additional logic added inside of the function such as running a perl script, retrieving an element, etc.
var callback =
{
getProp1: function( )
{
return "Property 1 value";
},
getProp2: function( )
{
return "Property 2 value";
}
}
The other piece of the server script is the precursor to launching the client script, the fragment below sets up an array of variable names and variable values. The makeRemote is the key piece to allowing a clientscript to be able to access the serverscript functions. The actual calling of server side function is not required, but it is an option. The other option is to have the serverside script gather all the details it needs and then set up the variables and invoke the clientscript with them.
var flds = new Array(); var vals = new Array(); flds[0] = "callback"; vals[0] = formula.util.makeRemote( callback );
In the server script we now have two functions (getProp1 and getProp2) and a way to call them (callback variable). To call the function within the clientscript, just use: callback.getProp1()
Below are the complete scripts. Copy both scripts into \nocInstallDirector\database\scripts. Set up an element operation that is a serverscript, with a load on helloworldserver.fs.
Helloworldclient.fs
var str = "Prop1: " + callback.getProp1() + '\n'; str += "Prop2: " + callback.getProp2() info( str );
HelloWorldServer.fs
var callback =
{
getProp1: function( )
{
return "Property 1 value";
},
getProp2: function( )
{
return "Property 2 value";
}
}
var flds = new Array();
var vals = new Array();
flds[0] = "callback";
vals[0] = formula.util.makeRemote( callback );
session.invokeScript( "Hello World", "load( 'helloworldclient.fs' ); ", vals, flds );
This is just a starting point, this can be used many ways. The server script can do up front work prior to calling the client script and then based on clientscript logic, additional serverside functions could be called to do even more things. Enjoy.
- Tobin
Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).
It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.
Related Articles
User Comments
- tisenberg's blog
- Be the first to comment! To leave a comment you need to Login or Register
- 2663 reads


0