{"record":{"id":"f7b1e260a3600785","repo":"windmill-labs/windmill","slug":"you-can-t-use-this-function-in-a-standalone-script","errorCode":null,"errorMessage":"You can't use this function in a standalone script or flow step preview. Please use it in a flow or a flow preview.","messagePattern":"You can't use this function in a standalone script or flow step preview\\. Please use it in a flow or a flow preview\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"typescript-client/client.ts","lineNumber":1354,"sourceCode":" * ```\n *\n * **Note:** This function requires execution within a Windmill flow or flow preview.\n */\nexport async function requestInteractiveSlackApproval({\n  slackResourcePath,\n  channelId,\n  message,\n  approver,\n  defaultArgsJson,\n  dynamicEnumsJson,\n  resumeButtonText,\n  cancelButtonText,\n}: SlackApprovalOptions): Promise<void> {\n  const workspace = getWorkspace();\n  const flowJobId = getEnv(\"WM_FLOW_JOB_ID\");\n\n  if (!flowJobId) {\n    throw new Error(\n      \"You can't use this function in a standalone script or flow step preview. Please use it in a flow or a flow preview.\"\n    );\n  }\n\n  const flowStepId = getEnv(\"WM_FLOW_STEP_ID\");\n  if (!flowStepId) {\n    throw new Error(\"This function can only be called as a flow step\");\n  }\n\n  // Only include non-empty parameters\n  const params: {\n    approver?: string;\n    message?: string;\n    slackResourcePath: string;\n    channelId: string;\n    flowStepId: string;\n    defaultArgsJson?: string;\n    dynamicEnumsJson?: string;","sourceCodeStart":1336,"sourceCodeEnd":1372,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/typescript-client/client.ts#L1336-L1372","documentation":"slackApproval (Slack approval helper) requires the flow job id environment variable (WM_FLOW_JOB_ID), which Windmill only injects when code runs inside a flow (or a flow preview). In a standalone script or flow-step preview the variable is absent, so the client throws to prevent an approval that could never resolve.","triggerScenarios":"Calling slackApproval(...) from a standalone script run or from a flow step preview where WM_FLOW_JOB_ID is not set.","commonSituations":"Testing approval code with 'run this step only' (preview) instead of a full flow run; moving a flow step's code into a standalone script and forgetting the function is flow-only.","solutions":["Run the code as part of a full flow execution, not a standalone script or step preview","Use the flow preview mode that sets flow context (flow preview, not step preview)","Guard the call with a check for WM_FLOW_STEP_ID / WM_FLOW_JOB_ID and provide an alternative path for tests","Mock getEnv in unit tests for the approval logic"],"exampleFix":"// before (inside a standalone script)\nawait slackApproval({ channel: 'C123', text: 'Deploy?' })\n// after — only call within a flow, or guard it\nif (getEnv('WM_FLOW_JOB_ID')) {\n  await slackApproval({ channel: 'C123', text: 'Deploy?' })\n} else {\n  console.log('skipping approval outside flow context')\n}","handlingStrategy":"validation","validationCode":"if (!getEnv('WM_FLOW_JOB_ID')) {\n  throw new Error('slackApproval requires a flow context; run inside a flow, not a standalone script or step preview')\n}","typeGuard":"function inFlowContext(): boolean {\n  return !!getEnv('WM_FLOW_JOB_ID')\n}","tryCatchPattern":"try {\n  await slackApproval(opts)\n} catch (e) {\n  if (e.message.includes('standalone script or flow step preview')) {\n    console.error('Call slackApproval only from a real flow run')\n  } else throw e\n}","preventionTips":["Only use approval helpers from flow steps, never standalone scripts","When testing, use full flow preview runs rather than single-step previews","Guard approval code behind an inFlowContext() check in shared modules"],"tags":["flow","environment","context","slack","approval"],"backgroundTag":"flow-context-required","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}