You can call any Caché class method or Caché/GT.M extrinsic function from within a Javascript function or Event Handler by prefixing ewd: to the method or function name. The class method or extrinsic function should have a returnValue that is either a null string or a string of Javascript commands. If you return a null string, nothing will happen within the browser. If you return a string of Javascript, it is automatically executed (using eval()) when received by the browser. The amount of Javascript you can return is dictated by your back-end system. For example, Caché 5.x systems limit you to 32k.

Your class method/function can have as many parameters as you wish, and you pass Javascript and/or literal values into those parameters. The values are automatically mapped into corresponding Caché variables. For example:

There are two ways to call the Event Broker:

Within an Event Handler
  onClick="ewd:##class(ewd.test).myFunc(,this.value,'hello world')"
Within a Javascript Function

The Event Broker call should be on its own line, with no preceeding characters other than whitespace characters, for example:

  <script language="javascript>
    function myExample1(name,value) {
       ewd:##class(ewd.test).myFunc(name,value,'hello world') ;
    function myExample2(name,value) {
       ewd:myFunc^myRoutine(name,value,'hello world') ;

Script structure

The corresponding method/function for the above example would be structured as follows:

Class Method
ClassMethod myFunc(name As %String, value As %String, hello As %String, 
               sessid As %String) As %String
// processing takes place here
QUIT "alert('processing completed') ;"

Note that although the Session Id (sessid) is not specified in the Event Broker call within your EWD page, it must be declared in the class method.

Extrinsic Function
  ; processing takes place here
  set myVar = $$getSessionValue^%zewdAPI("myVar",sessid)
  ; ...etc 
  QUIT "document.getElementById('field1').value = 'hello there!' ; alert('finished') ;"

Note that if you use an extrinsic function, you should not declare the session ID (sessid) as a parameter. EWD makes it implicitly available to you (as a globally scoped local variable) as the variable sessid.