Name:demo-set-context
Type:script
Source:demo-set-context-def.psm1
set context with cycleNo
and month
context
This runs after the *params* function
function getTaskDesc([Task]$task) {
[string]$desc = @"
This illustrates how to manage the global workflow context for subsequent tasks.
"@
return $desc;
}
set parameters with current date
context
The *brief* variable is set so that the *primeContextTask* has access to it.
function primeContextTask([Task]$task, [hashtable]$brief) {
$tfs = $task.tfs;
$tfs.globMap.demoGlobs.cycleNo = 0;
if (exists $brief cycleNo) {
$tfs.globMap.demoGlobs.cycleNo = $brief.cycleNo / 1;
}
if (exists $brief month) {
$tfs.globMap.demoGlobs.month = $brief.month;
}
hlogBoth("Running primeContextTask $($task.name) $($tfs.globMap.demoGlobs.month) $($tfs.globMap.demoGlobs.cycleNo) $($brief.cycleNo)")
[void]($task.find("opt-cycleNo").setText("$($tfs.globMap.demoGlobs.cycleNo)"));
}
set options with month
and starting cycleNo
context
This runs before the *params* function and the values set here are passed to it.
function params {
param([Object]$task,[hashtable]$htOpts)
$tfs = $task.tfs;
$date = Get-Date
[string]$dateStr = $date.ToString("yyyyMMdd")
$htOpts.datestr = $dateStr;
$htOpts.brief = "$($task.statlocn)"
return $htOpts
}
run context script
context
This example increases the `cycleNo` whenever the *runScript* function is run.
function options {
param([Object]$task)
$opts = @();
$tfs = $task.tfs;
$opts += @{type='input'; parm="cycleNo"; label='CycleNo'; place='cycloNo'; readonly=$true}
$opts += @{type='combo'; parm='month'; label='Month'; valset='jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec'}
hlogBoth("fetch.options $($tfs.globMap.demoGlobs.month) $($tfs.globMap.demoGlobs.cycleNo)")
return ,$opts
}
run context script
context
This example increases the `cycleNo` whenever the *runScript* function is run.
function runScript([Task]$task, [hashtable]$parms, [hashtable]$status) {
$tfs = $task.tfs;
$status.month = $tfs.globMap.demoGlobs.month = $parms.month;
$status.cycleNo = $tfs.globMap.demoGlobs.cycleNo = $tfs.globMap.demoGlobs.cycleNo + 1;
hlogBoth("Running script $($task.name) $($tfs.globMap.demoGlobs.month) $($tfs.globMap.demoGlobs.cycleNo)")
[void]($task.find("opt-cycleNo").setText("$($tfs.globMap.demoGlobs.cycleNo)"));
}
Copyright © 2018-2021, 2022, Rexcel System Inc.