rubenf
rubenf6mo ago

how do you set and get flow user states

@Ask Inkeep how do you set and get flow user states
3 Replies
Ask Inkeep
Ask Inkeep6mo ago
Thanks for tagging me @rubenf. I'll look through relevant sources and get back to you shortly. ----------------------------- While I generate an answer, here are some sources that might be helpful: * Within Windmill: Not recommended * set flow user state POST /w/{workspace}/jobs/flow/user_states/{id}/{key} * Architecture and Data Exchange * Resources and Resource Types -----------------------------
Ask Inkeep
Ask Inkeep6mo ago
Answer To set and retrieve user states within a flow in Windmill, you can use the provided TypeScript and Python examples as guidance. For setting a custom flow user state, you can use the following TypeScript and Python code snippets: TypeScript:
import * as wmill from "windmill-client@1.297.0"

export async function main(x: string) {
await wmill.setFlowUserState("FOO", 42)
return await wmill.getFlowUserState("FOO")
}
import * as wmill from "windmill-client@1.297.0"

export async function main(x: string) {
await wmill.setFlowUserState("FOO", 42)
return await wmill.getFlowUserState("FOO")
}
Python:
import wmill
#extra_requirements:
#wmill==1.297.0

def main(x: str):
wmill.set_flow_user_state("foobar", 43)
return wmill.get_flow_user_state("foobar")
import wmill
#extra_requirements:
#wmill==1.297.0

def main(x: str):
wmill.set_flow_user_state("foobar", 43)
return wmill.get_flow_user_state("foobar")
(1) These examples demonstrate how to set a value using setFlowUserState and then retrieve it with getFlowUserState within the same flow. These functions allow for the storage of data across steps in a flow, accessible globally within that flow. For more details on how to programmatically interact with flow user states via the Windmill API, please refer to the set flow user state (2) and get flow user state (3) documentation.
Ask Inkeep
Ask Inkeep6mo ago
Glad I could be helpful. Feel free to create a new thread with any new questions you may have.