Page tree
Skip to end of metadata
Go to start of metadata

The Action Type option in SWAT supports the 'INVOKE' setting. This exists as an option in menuFunctions and offers an easier and standardized method of calling back-end logic. The actual BusinessTask call is done automatically by the framework, and the BusinessTask parameters can be set from the menuFunction. Furthermore, any other checks, validations or parameter settings are supported (before and after the backend call) by defining two JavaScript events: eventPre and eventPost.

Sample of a menuFunction: 

  • Action Target - the BusinessTask class name

  • Action Parameter - the method name to be called from the BusinessTask

  • Action Options - list of options/settings for the invokeServerTask method, as a list in a valid JSON format

  • Event pre - client logic method which is called before the BusinessTask call to the backend. Receives two parameters: eventSource (the context) and params (the menuFunction options)

  • Event post - client logic method which is called after the BusinessTask call to the backend. Receives two parameters: eventSource (the context) and params (the backend response)


Sample for Event pre, if it would be called from a Toolbar button:

export function eventPre( Toolbar : akioma.swat.Toolbar, Options: any) {

	const parameters= {
?? ??		param1 : value1,
?? ??		param2: value2
	};

	Options.optionsJSON.uiContext = Toolbar.parent.dynObject;
	Options.params = { dsTest: { eTest: [ TestData]},
		plcParameter: parameters
	};

	return Options;

}

The method receives two parameters: Toolbar and Options. Toolbar would be the controller from where the action was triggered and Options contains the menuFunction options. 


Sample of the Options parameter:

eventPost: "$ akioma.eventPost(eventSource, params);"
eventPre: "$ akioma.eventPre(eventSource, params);"
methodName: "MethodBT"
name: "Akioma.Swat.BT"
options: "{'showWaitCursor': true}"
optionsJSON: {showWaitCursor: true}
params: {plcParameter: {}}

The Options parameter can be configured here. The method name of the BusinessTask can be changed, more options can be set for the invokeServerTask call (see Options.optionsJSON in the sample above) and the BusinessTask parameters need to be set here. The method needs to return the Options and afterwards they'll be used for the actual backend call.


After the backend call is done, the Event post will be called. 

Sample for Event post: 

export function eventPost( Toolbar : akioma.swat.Toolbar, Result: any) {

	if (Result.error) {
		// client logic for error handling 
	} else {
		// client logic for success handling
	}

}

The method receives two parameters: Toolbar and Result. Toolbar would be the controller from where the action was triggered and Result contains the backend response.

The Result parameter can either contain the backend error object (in case of error), or the backend return object (in case of success). 

  • No labels