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 : |
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>