{"record":{"id":"9c78783edc1a05ca","repo":"OrchardCMS/OrchardCore","slug":"the-retrievecontenttask-failed-to-evaluate-the-contentitemid","errorCode":null,"errorMessage":"The 'RetrieveContentTask' failed to evaluate the 'ContentItemId'.","messagePattern":"The 'RetrieveContentTask' failed to evaluate the 'ContentItemId'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/RetrieveContentTask.cs","lineNumber":33,"sourceCode":"        IWorkflowScriptEvaluator scriptEvaluator,\n        IStringLocalizer<RetrieveContentTask> localizer)\n        : base(contentManager, scriptEvaluator, localizer)\n    {\n    }\n\n    public override string Name => nameof(RetrieveContentTask);\n\n    public override LocalizedString DisplayText => S[\"Retrieve Content Task\"];\n\n    public override LocalizedString Category => S[\"Content\"];\n\n    public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n        => Outcome(S[\"Retrieved\"]);\n\n    public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n    {\n        var contentItemId = (await GetContentItemIdAsync(workflowContext))\n            ?? throw new InvalidOperationException($\"The '{nameof(RetrieveContentTask)}' failed to evaluate the 'ContentItemId'.\");\n\n        var contentItem = (await ContentManager.GetAsync(contentItemId, VersionOptions.Latest))\n            ?? throw new InvalidOperationException($\"The '{nameof(RetrieveContentTask)}' failed to retrieve the content item.\");\n\n        if (string.IsNullOrEmpty(workflowContext.CorrelationId))\n        {\n            workflowContext.CorrelationId = contentItem.ContentItemId;\n        }\n\n        workflowContext.Properties[ContentEventConstants.ContentItemInputKey] = contentItem;\n        workflowContext.LastResult = contentItem;\n\n        return Outcome(\"Retrieved\");\n    }\n}\n","sourceCodeStart":15,"sourceCodeEnd":49,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/RetrieveContentTask.cs#L15-L49","documentation":"RetrieveContentTask evaluates a ContentItemId expression and throws InvalidOperationException when it cannot produce a value. This means the configured expression (e.g. a workflow variable or Liquid/JS expression) evaluated to null or empty. The workflow activity refuses to proceed without a target content item ID.","triggerScenarios":"GetContentItemIdAsync(workflowContext) returns null because the 'ContentItemId' expression property of the activity is empty, references a non-existent workflow variable, or the expression evaluates to null at runtime.","commonSituations":"Workflow designer misconfiguration: the ContentItemId field was left blank, a preceding task that sets the variable didn't run, or the variable name is misspelled (case-sensitive).","solutions":["Open the workflow definition and set a valid ContentItemId expression on the RetrieveContentTask activity.","Verify the referenced workflow variable exists and is populated by an earlier activity (e.g. ContentCreatedEvent output).","Test the expression in isolation (e.g. a Code/Log task printing the value) to confirm it resolves.","Wrap the workflow path so the task only runs when the variable is set, or use a different event providing a content item."],"exampleFix":"// before (activity property)\nContentItemId: \"\"  // blank or typo'd variable\n// after\nContentItemId: \"{{ Workflow.Input.ContentItem.ContentItemId }}\"","handlingStrategy":"validation","validationCode":"// Before the workflow task runs, in a preceding condition/code activity:\nvar id = (string)workflowContext.Input.GetValue(\"ContentItemId\") ?? (string?)workflowContext.GetProperty(\"ContentItemId\");\nif (string.IsNullOrWhiteSpace(id)) throw new InvalidOperationException(\"RetrieveContentTask: ContentItemId must be set before execution.\");","typeGuard":null,"tryCatchPattern":"try { await task.ExecuteAsync(workflowContext, activityContext); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"failed to evaluate the 'ContentItemId'\"))\n{\n    logger.LogWarning(ex, \"ContentItemId expression unresolved; skipping retrieve step.\");\n}","preventionTips":["Always populate the ContentItemId expression in the workflow designer.","Reference event outputs (ContentItem.ContentItemId) rather than hand-typed IDs.","Test the expression with a Log/Notify task before the retrieve.","Name workflow variables consistently and avoid case typos."],"tags":["workflows","content","configuration","null-value"],"backgroundTag":"missing-required-argument","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}