Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
user_defined_functions [2020/04/26 03:33]
127.0.0.1 external edit
— (current)
Line 1: Line 1:
-===== User Defined Function ===== 
- 
-User Defined Functions can improve the re-usability of your mscripts. User defined functions are first declared in //function// trigger in the model. There is no limit on the number of user functions you may define. 
- 
-Below is an example of a user function: 
- 
-{{http://testoptimal.com/img/UserFunc.jpg}} 
- 
----- 
- 
-==== Declare User Defined Function ==== 
- 
-You can create as many user defined functions as you want. Each user defined function is declared with //func// tag that has a //name// attribute . 
-  <func name="func1"> 
-      <log msg="inside func1: parameters are $listParam()"/> 
-      <action code="$setFuncReturn('return value')"/> 
-  </func> 
-    
-User defined function can take 0 or any number of parameters. Parameters are specified as key=value pairs. Multiple parameters are passed in separately, e.g. 
- 
-  $callFunc('func1','lastName=smith','firstName=john') 
- 
-Within the //func// tag, you add any mscript tags and methods. You can access the parameters passed into the function with mscript method //$getFuncParam('lastName')//. 
- 
----- 
-==== Return Value ==== 
-Optionally you can return a value. You can do so with mscript method //$setFuncReturn('returnValue')//. Multiple calls to this method overrides the return value and only the value of the last call is returned. 
- 
-Below is an example of a user defined function that returns a full name: 
- 
-  <func name='getFullName'> 
-      <action code="$setFuncReturn('$getFuncParam('lastName'), $getFuncParam('firstName')')"/> 
-  </func> 
- 
- 
----- 
-==== Call User Defined Function ==== 
-To call this user defined function, use mscript method //$callFunc('funcName','param1','param2')//. For example: 
- 
-  <log msg="Full Name is: $callFunc('getFullName','lastName=Smith','firstName=John')"/> 
-      
- 
----- 
-==== Accessing Parameters==== 
-Inside the user function, you can access the input parameters with $getFuncParam('paramName'). For example $getFuncParam('lastName') to retrieve parameter 'lastName' which should return 'Smith' in the above example. 
- 
- 
-User function may call another user function with //$callFunc(...)// using the above calling syntax.  Be sure that you don't cause infinite recursive loop. 
-