temporal icon indicating copy to clipboard operation
temporal copied to clipboard

How to query all workflows with a particular search parameter

Open sreepadmaparamesvaraiyer opened this issue 2 years ago • 1 comments

I have below query - I have a object X added to workflowInterface and there is a query method on it , how do query all workflows which have X.variableName = 'value'

List<WorkflowExecutionInfo> workflows = serviceStubs .blockingStub() .listWorkflowExecutions( ListWorkflowExecutionsRequest .newBuilder() .setNamespace(observer.getNamespace()) .setQuery("WorkflowType="MyWorkflow"") .build() ).getExecutionsList();

You can use search attribute to do what you want. First, you need to register your search attribute: https://docs.temporal.io/cloud/tcld/namespace/search-attributes/add/ Then, in your workflow code, you will do something like: UpsertSearchAttribute("MySearchAttributeName", "MyValue")

Then, in your ListWorkflow call, you apply filter like 'MySearchAttributeName = "MyValue"'

yiminc avatar Aug 19 '22 18:08 yiminc

@yiminc Can this be automatic? eg: We can directly query the payload passed to the workflow etc in the Web UI

Thanks

wahmedswl avatar Jan 21 '23 12:01 wahmedswl

You need to 1) register your search attribute (this is a one time job); 2) tag your workflow with your search attribute. This cannot be automated because temporal server don't know about your search attribute. For step 2, if you know the value for your search attribute when you start your workflow (as you mentioned based on input), then you could set SearchAttributes when you start your workflow (it is part of start workflow request)

yiminc avatar Aug 27 '23 20:08 yiminc