ExecuteFunction: run a previously declared function
The ExecuteFunction tag allows to execute a function that was previously declared in the script.
Detailed Description
Runs a function, with all its local variables and lists reset (as if they had never existed).
Can use the same Echo and OnError parameters as its declaration. If set, they override the default values set in the declaration. If unset, these default values apply.
Tag Attributes
Attributes | Value Description |
---|---|
Name | Any unreserved name valid in XML. Reserved names are listed on: Variables Required |
Echo | True: turn echo on False: turn echo off Default (value not set): current script setting |
OnError | Local: bypass script OnError setting and use default OnError settings; <OnError …/> tags inside the function remain local and do not alter the main script Global: use main script current OnError setting Default: Global NB: if Global and an <OnError …/> action tag appears inside the function, it sets the main script error management. |
List | Names of local lists that are visible and that can be modified in a function called form another function. Global lists are always visible and can always be modfied from any function without using the List paramter. Separate the list name with a semi-colon : |
INPUT_ | Prefix of the name of any function parameter. A parameter is a local variable that can be initialized with a value at function execution time. |
RETURN_ | Prefix of the name of any local variable returned by the function. The scope of such a variable becomes the scope of the caller (another function, or the main script). |
INPUTLIST_ | Prefix of the name of any local list that can be initialized from the content of another list. This list remains local and is cleared when the function exits. |
NB: sapio365 job presets parse the function for each call, not at declaration time.
Example Scripts
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<ytriaAutomation Console="True">
<list name="ListGlobal" Action="setVar" Dname="L1"/>
<list name="ListGlobal" Action="setVar" Dname="L2"/>
<list name="ListGlobal" Action="setVar" Dname="L3"/>
<SetVar GlobalVar="Top level var"/>
<SetVar FirstFunction="F1"/>
Declare function Local OnError and no trace:
<function name="{%FirstFunction%}" OnError="Local" echo="false">
local error mgt:
<OnError continue="true" MsgBox="Function error!"/>
<echo value="+++++++++ Let us run {%FirstFunction%}"/>
<echo value="global var: {%GlobalVar%}"/>
<echo value ="Size of ListGlobal in {%FirstFunction%} = {%lSize%}"/>
error:
<Unselect/>
<list name="ListLocal" Action="setVar" Dname="O1"/>
<list name="ListLocal" Action="setVar" Dname="O2"/>
<SetVarListSize localSize='ListLocal'/>
<echo value ="Size of ListLocal in {%FirstFunction%} = {%localSize%}"/>
<echo value="Before set local var: {%LocalVar%}"/>
<SetVar LocalVar="LocalVar"/>
<echo value="After set local var: {%LocalVar%}"/>
<list name="ListGlobal" Action="setVar" Dname="L4 added in {%FirstFunction%}"/>
<SetVar GlobalVar="This text was set in {%FirstFunction%}"/>
<breakLoop/>
<echo value="After break, should not display"/>
</function>
<SetVarListSize lSize='ListGlobal'/>
<echo value ="MAIN size of ListGlobal {%lSize%}"/>
<echo value ="MAIN GlobalVar = '{%GlobalVar%}'"/>
<echo value="About to run function {%FirstFunction%} with default echo off/local OnError"/>
run function:
<executeFunction name="{%FirstFunction%}"/>
<SetVarListSize lSize='ListGlobal'/>
<echo value ="MAIN size of ListGlobal {%lSize%}"/>
<echo value ="MAIN GlobalVar in Main = '{%GlobalVar%}'"/>
Check if variables set in function are visible:
<echo value="MAIN ********* local var: '{%LocalVar%}' * should be empty"/>
<echo value="MAIN ********* Size of ListLocal: '{%localSize%}' * should be empty"/>
NB: these variables are now global, next function call will not erase them
error:
<Unselect/>
<echo value="After error in main, should not display"/>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<ytriaAutomation Console="True">
<echo mode='false'/>
<function Name='test'>
<Clear List='share1'/>
<Clear List='share2'/>
<list name='share1' action='setvar' val='A'/>
</function>
<function Name='Main'>
<list name='share1'/>
<list name='share2'/>
<ExecuteFunction Name='test' list="share1;share2"/>
<if Mode='Exists' Test='share1' Value='True' Target='list'>
<echo value='share1 YES'/>
<Loop List='share1'>
<ExecuteListAction/>
<echo value='share1 -- val={%val%}'/>
</Loop>
</if>
<if Mode='Exists' Test='share2' Value='True' Target='list'>
<echo value='share2 YES'/>
<Loop List='share2'>
<ExecuteListAction/>
<echo value='share2 -- val={%val%}'/>
</Loop>
</if>
</function>
<echo value='# BEFORE ################'/>
<if Mode='Exists' Test='share1' Value='True' Target='list'>
<echo value='share1 YES'/>
<Loop List='share1'>
<ExecuteListAction/>
<echo value='share1 -- val={%val%}'/>
</Loop>
</if>
<if Mode='Exists' Test='share2' Value='True' Target='list'>
<echo value='share2 YES'/>
<Loop List='share2'>
<ExecuteListAction/>
<echo value='share2 -- val={%val%}'/>
</Loop>
</if>
<echo value='# '/>
<echo value='# ONE ################'/>
<ExecuteFunction Name='Main'/>
<echo value='# '/>
<echo value='# TWO ################'/>
<ExecuteFunction Name='Main'/>
<echo value='# '/>
<echo value='# AFTER ################'/>
<if Mode='Exists' Test='share1' Value='True' Target='list'>
<echo value='share1 YES'/>
<Loop List='share1'>
<ExecuteListAction/>
<echo value='share1 -- val={%val%}'/>
</Loop>
</if>
<if Mode='Exists' Test='share2' Value='True' Target='list'>
<echo value='share2 YES'/>
<Loop List='share2'>
<ExecuteListAction/>
<echo value='share2 -- val={%val%}'/>
</Loop>
</if>
</ytriaAutomation>
Example with INPUT_, RETURN_ and INPUTLIST_
In the function
PRINTVAR
,INPUT_V1
is used as parameter,RETURN_1
andRETURN_2
are set (and become global variables whenPRINTVAR
is called from top level),INPUTLIST_FULL
andINPUTLIST_EMPTY
are local lists;INPUTLIST_FULL
is initialized at execution time with the content oflist1
:
<Function Name='SubProcess'>
<SetVar RETURN_SUB="RETURN FROM SUB"/>
</Function>
<Function Name='PRINTVAR'>
<echo value='> return SUB: {%RETURN_SUB%}'/>
<ExecuteFunction Name='SubProcess'/>
<echo value='> return SUB: {%RETURN_SUB%}'/>
<SetVar RETURN_1="{%INPUT_V1%}"/>
<SetVar RETURN_2="RV2"/>
<LIST NAME="INPUTLIST_FULL" ACTION="SetVar" MyVar="the second var"/>
<LIST NAME="INPUTLIST_FULL" ACTION="SetVar" MyVar="the third var"/>
<loop list="INPUTLIST_FULL">
<ExecuteListAction/>
</loop>
<LIST NAME="INPUTLIST_EMPTY" ACTION="SetVar" MyVar="the chaise var"/>
<LIST NAME="INPUTLIST_EMPTY" ACTION="SetVar" MyVar="the throne var"/>
<loop list="INPUTLIST_EMPTY">
<ExecuteListAction/>
</loop>
</Function>
<LIST NAME="list1" ACTION="SetVar" MyVar="the first var"/>
<echo value='--------------------------------------'/>
<ExecuteFunction Name='PRINTVAR' INPUT_V1='V111' INPUTLIST_EMPTY="Chaise" INPUTLIST_FULL="list1"/>
<echo value='> return 1: {%RETURN_1%}'/>
<echo value='> return 2: {%RETURN_2%}'/>
<echo value='> return SUB: {%RETURN_SUB%}'/>
<loop list="list1">
<ExecuteListAction/>
</loop>
<loop list="INPUTLIST_EMPTY">
<ExecuteListAction/>
</loop>
<loop list="INPUTLIST_FULL">
<ExecuteListAction/>
</loop>
