conductor
conductor copied to clipboard
How to set the EffectiveDate for WateFor event in JSON?
Hi,
I have the following workflow definition:
{
"Id": "AutomaticReply",
"Steps": [
{
"Id": "OnMoReceived",
"StepType": "While",
"Inputs": {
"Condition": "1"
},
"Do": [[
{
"Id": "WaitForMo",
"StepType": "WaitFor",
"Inputs": {
"EventName": "\"MoReceived\"",
"EventKey": "\"MOIN\"",
"EffectiveDate": "DateTime.Now"
},
"Outputs": {
"Mo": "step.Data"
},
"NextStepId": "SendMt"
},
{
"Id": "SendMt",
"StepType": "HttpRequest",
"Inputs": {
"BaseUrl": "http://localhost:5006/api/v1/test/",
"Resource": "message",
"Method": "POST",
"Headers":{
"@Authorization": "Bearer xxx",
"@Content-Type": "application/json"
},
"Body": {
"destination": "data.Mo.Source",
"text": "data.Mo.Text"
}
}
}
]]
}
]
}
When I start this workflow (I'm using Conductor) using the http request:
curl --location --request POST 'http://localhost:5000/api/workflow/AutomaticReply' \
--header 'Content-Type: application/json' \
--data-raw '{
}'
I get the following exception
fail: WorkflowCore.Services.WorkflowExecutor[0]
Workflow 5f5889a91cf3171bf042a51b raised error on step 1 Message: name 'DateTime' is not defined
IronPython.Runtime.UnboundNameException: name 'DateTime' is not defined
at IronPython.Runtime.Operations.PythonOps.GetVariable(CodeContext context, String name, Boolean isGlobal, Boolean lightThrow)
at IronPython.Compiler.LookupGlobalInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at IronPython.Compiler.PythonScriptCode.EvalWrapper(CodeContext ctx)
at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
at Microsoft.Scripting.SourceUnit.Execute(Scope scope)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at Conductor.Domain.Scripting.ScriptEngineHost.EvaluateExpression(String expression, IDictionary`2 inputs) in C:\Users\conductor\src\Conductor.Domain.Scripting\ScriptEngineHost.cs:line 33
at Conductor.Domain.Services.ExpressionEvaluator.EvaluateExpression(String sourceExpr, Object pData, IStepExecutionContext pContext) in C:\Users\conductor\src\Conductor.Domain\Services\ExpressionEvaluator.cs:line 22
at Conductor.Domain.Services.WorkflowLoader.<>c__DisplayClass12_0.<BuildScalarInputAction>g__acn|0(IStepBody pStep, Object pData, IStepExecutionContext pContext) in C:\Users\conductor\src\Conductor.Domain\Services\WorkflowLoader.cs:line 258
at WorkflowCore.Models.ActionParameter`2.Assign(Object data, IStepBody step, IStepExecutionContext context)
at WorkflowCore.Models.ActionParameter`2.AssignInput(Object data, IStepBody body, IStepExecutionContext context)
at WorkflowCore.Services.WorkflowExecutor.ExecuteStep(WorkflowInstance workflow, WorkflowStep step, ExecutionPointer pointer, WorkflowExecutorResult wfResult, WorkflowDefinition def)
at WorkflowCore.Services.WorkflowExecutor.Execute(WorkflowInstance workflow)
How do I set DateTime.Now in json? I'm following the syntax given here.
Have you tried a JSON datetime like 2012-04-23T18:25:43.511Z ?
I need to set the datetime dynamically to the current time, hence the attempt to use DateTime.Now. It might even be a good idea to set the default EffectiveDate to DateTime.Now instead of DateTime.Min as it is easier to specify a hardcoded old date to process all received events actually.
Maybe try System.DateTime.Now?
This is not the same as workflow core... the scripting engine here is Python
see https://conductor-core.readthedocs.io/en/latest/primitives/
Maybe try datetime.now()