Trigger

Sometimes it is necessary to start a workflow from another one.

Therefore we have prepared cmdlet Invoke-KFWorkflow.

You can only trigger SharePoint workflows (list, state machine, site) and PowerShell workflows.

There you name the workflow by its id and optionally specify a list item id.

The called workflow is started. The trigger is passed as event to the workflow script in parameter $eventData.

The $eventData object will be a PowerShell Hashtable with this entries:

Data cann be passed to the called workflow with the -Data parameter of Invoke-KFWorkflow.

The data that is transfered to the called workflow must be serializable. It's not possible to transfer complex object such as System.IO.Stream.

Return Data

It is possible to send data back to the caller.

Here are two workflows.

The "Caller" config (_wfconfig.ps1):

@{
	Version = "4.0";
	Ignore = $true; 
	Type = "SHAREPOINT";
	SubType = "SITE";
	Name = "trigger-sender"; 
	Platform = "sp2013"; 
	Id = "52989b84-43c5-4db8-ae10-4f04dcb03e6c"; 
	TBE = 60; 
	CustomLibrary = ""; 
	spUser = "sharepoint\kenaflow";
	spPwd = 'kr@ftwerk';
	Web = "https://intranet13.sharepoint.farm"; 
	Script = "script.ps1";
}

if(!$kenaflow){import-module "C:\Program Files\kenaflow\kenaflow.runtime.dll";Test-KFConfig;exit}

The workflow script script.ps1

param($wf, $web, $config, $eventData)

if($wf-eq$null){import-module "C:\Source\wfengine\bin1\Debug\kenaflow.runtime.dll";
  Invoke-Kenaflow -Breakpoint;exit}

$result = 
  (Invoke-KFWorkflow \`
    -WorkflowId "8808aecd-f7e5-444c-a625-0d1506c2e99c" \` 
    -WithAnswer -AnswerTimeout 10000)

Write-KFLog "kenaflow is $($result.kenaflow)!"

The called workflows config (_wfconfig.ps1):

@{
	Version = "4.0";
	Ignore = $false; 
	Type = "POWERSHELL";
	Name = "trigger-receiver"; 
	Id = "8808aecd-f7e5-444c-a625-0d1506c2e99c"; 
	TBE = -1; 
	RER = $true; 
	Script = "script.ps1";
}

The called workflows script (script.ps1):

param($wf, $web, $item, $config, $eventData)

if($wf-eq$null){import-module "C:\source\wfengine\bin1\Debug\kenaflow.runtime.dll";
  Invoke-Kenaflow -debug -verbose;exit}

return @{kenaflow="cool"}

The first workflow will output "kenaflow is cool!" to the log. "cool" comes from the called workflow as return value.

The return data must be serializable!