OpenWGA 7.10 - TMLScript reference

Method :

callAction([context], actionID, [param1, .... param5])

On object WGA
Usage Calls a WebTML action
Description This can be used to call WebTML actions that are defined in any allowed way, including master and async actions.

In case of a master action the call is automatically executed in a separate session. Data changes done in this master action will not be automatically visible to the calling code as its current database session will not pick them up. To have the updated state in the calling code you can reopen the current session of changed databases after the action call (see examples), but note that this will drop all unsaved changes to these databases from the calling session.

In case of an async action the call of the action is triggered but the calling TMLScript code continues while the action is executed.

As usual the parameters param1 to param5 will be available to the action as WebTML variables "tmlparam1" to "tmlparam5" and as List object "actionParams" containing the params as list elements 0 to 4.

For backward compatibility there still is a global function "callAction()" available whose use is discouraged since OpenWGA 5.3.

Parameters context (TMLContext, optional):
A context in which the action is to be executed. Omit this to have the action execute under the same main context as the calling script.

actionID (String):
ID of the action to call. This may be the ID of a <tml:action> tag or the name of a TMLScript module. If you want to call an action that is defined in a different applications design you may prefix the ID with the database key of this application plus a slash. So to call an action "actions:doit" from application "myapp", use "myapp/actions:doit" as ID parameter.

param1, ...param5 (Optional)
Parameters for the action
Return value Return value of the action if it finishes with a "return" statement
Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
Examples A frequent use case for callAction() is to call a master action from a normal action. In this scheme the master action can perform operations that are not possible under the users rights while the calling normal action can perform operations that need the WebTML environment, which is not available in the master action.

The following example defines therefor two actions. The normal action "outerAction" - which might be directly called via URL - calls the master action "newSessionID".

The master action creates a new session ID by some tool method. It sets it as item to the document of unique name "home" and saves it.

Then execution is passed back to the calling action. It reopens the database session to gain access to the data modifications done by the master action (see description). Finally it sets a portlet variable to the newly created session ID (which would not be possible inside the master action).

<tml:action id="newSessionID" master="true">
  var content = db().getContentByName("home");
  var newID = Tool.generateSessionId();
  content.setItemValue("sessionid", newID);;

<tml:action id="outerAction">
  portlet.setVar("NewSessionID", context("name:home").sessionid);