{"record":{"id":"fedf0848501c1571","repo":"OrchardCMS/OrchardCore","slug":"the-syntax-syntax-isn-t-supported-for-foreachtask","errorCode":null,"errorMessage":"The syntax {Syntax} isn't supported for ForEachTask.","messagePattern":"The syntax (.+?) isn't supported for ForEachTask\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Workflows/Activities/ForEachTask.cs","lineNumber":87,"sourceCode":"    /// <summary>\n    /// The current number of iterations executed.\n    /// </summary>\n    public int Index\n    {\n        get => GetProperty(() => 0);\n        set => SetProperty(value);\n    }\n\n    public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n        => Outcome(S[\"Iterate\"], S[\"Done\"]);\n\n    public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n    {\n        var items = Syntax switch\n        {\n            WorkflowScriptSyntax.Liquid => await EvaluateLiquidEnumerableAsync(workflowContext),\n            WorkflowScriptSyntax.JavaScript => (await _scriptEvaluator.EvaluateAsync(Enumerable, workflowContext)).ToList(),\n            _ => throw new NotSupportedException($\"The syntax {Syntax} isn't supported for ForEachTask.\")\n        };\n\n        var count = items.Count;\n\n        if (Index < count)\n        {\n            var current = Current = items[Index];\n\n            // TODO: Implement nested scopes. See https://github.com/OrchardCMS/OrchardCore/projects/4#card-6992776\n            workflowContext.Properties[LoopVariableName] = current;\n            workflowContext.LastResult = current;\n            Index++;\n\n            return Outcome(\"Iterate\");\n        }\n        else\n        {\n            Index = 0;","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Workflows/Activities/ForEachTask.cs#L69-L105","documentation":"ForEachTask evaluates its Items expression using the scripting syntax stored on the activity (Syntax). Only Liquid (via the Liquid expression evaluator) and JavaScript (via the script evaluator) are implemented; any other WorkflowScriptSyntax value falls through the switch arm and throws NotSupportedException. This guards against a misconfigured or newly added enum value being used before it has an implementation.","triggerScenarios":"Executing a ForEachTask activity whose Syntax property is not WorkflowScriptSyntax.Liquid or WorkflowScriptSyntax.JavaScript, e.g. the enum default value (typically the first/0 member if it is not Liquid) left unset, a JSON workflow definition deserialized with an unknown/renamed syntax string, or a caller constructing ForEachTask programmatically without setting Syntax to a supported value.","commonSituations":"Hand-edited or generated workflow JSON with a stale syntax name after an SDK/module upgrade; a new WorkflowScriptSyntax member added upstream while the ForEachTask activity module was not rebuilt; code that news up ForEachTask and forgets to assign Syntax; data migration leaving old syntax values in stored activity properties.","solutions":["Set the ForEachTask activity's Syntax property to WorkflowScriptSyntax.Liquid and move the expression into the Liquid 'Items' (LiquidEnumerable) field.","Alternatively set Syntax to WorkflowScriptSyntax.JavaScript and provide the expression in the 'Enumerable' (JavaScript) field.","Inspect the stored workflow definition/activity properties for an invalid or legacy syntax value and correct or migrate it.","If a new syntax was recently added to WorkflowScriptSyntax, rebuild/update the OrchardCore.Workflows module so the switch handles it, or file/wait for an implementation of that arm."],"exampleFix":"// before\nvar forEach = new ForEachTask(); // Syntax left at default (unsupported value)\n// after\nvar forEach = new ForEachTask\n{\n    Syntax = WorkflowScriptSyntax.Liquid,\n    Items = new LiquidString { Expression = \"{{ Model.UserNames | json }}\" }\n};","handlingStrategy":"validation","validationCode":"// before executing\nif (forEachTask.Syntax is not (WorkflowScriptSyntax.Liquid or WorkflowScriptSyntax.JavaScript))\n    throw new InvalidOperationException($\"ForEachTask requires Liquid or JavaScript syntax; got {forEachTask.Syntax}\");","typeGuard":"static bool IsSupportedSyntax(WorkflowScriptSyntax s) => s is WorkflowScriptSyntax.Liquid or WorkflowScriptSyntax.JavaScript;","tryCatchPattern":"try { await activity.ExecuteAsync(workflowContext, activityContext); }\ncatch (NotSupportedException ex) { logger.LogError(ex, \"ForEachTask syntax unsupported: {Syntax}\", syntax); /* fail or fix activity */ }","preventionTips":["Always explicitly set Syntax when creating loop/task activities in code","Validate workflow JSON definitions against the supported syntax values before import","After upgrading OrchardCore.Workflows, grep stored definitions for syntax values no longer in the switch","Prefer Liquid for data-shaped expressions and JavaScript for logic; document the choice per activity"],"tags":["workflows","unsupported-enum-value","script-syntax","orchardcore"],"backgroundTag":"unsupported-enum-value","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}