# Check if workflow with workflow-id and/or run-id is open

**URL:** <https://community.temporal.io/t/check-if-workflow-with-workflow-id-and-or-run-id-is-open/738>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [October 14, 2020, 8:10am UTC](https://community.temporal.io/t/check-if-workflow-with-workflow-id-and-or-run-id-is-open/738 "2020-10-14T08:10:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nithin](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nithin](https://community.temporal.io/u/nithin)\
**Post date:** [October 14, 2020, 8:10am UTC](https://community.temporal.io/t/check-if-workflow-with-workflow-id-and-or-run-id-is-open/738/1 "2020-10-14T08:10:44Z")

</div>

I basically want to check if a workflow is open with the given type and workflow id, If it is open get the run id. [I looked around](https://community.temporal.io/t/how-to-get-last-runid/658/3) and couldn’t find a way to do this using using WorkflowClient, the only way seems to be to use DescribeWorkflowExecution api, please let me know if i am wrong.

Using the DescribeWorkflowExecution API how do i know if the workflow is open or closed? I do see a status field, could you let me know which of these status correspond to an open workflow? Is there a helper method for the same?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [October 14, 2020, 1:47pm UTC](https://community.temporal.io/t/check-if-workflow-with-workflow-id-and-or-run-id-is-open/738/2 "2020-10-14T13:47:56Z")

</div>

DescribeWorkflowExecution API is the way to go. If a workflow is open then

`DescribeWorkflowExecutionResult.workflowExecutionInfo.status` is equal to `WORKFLOW_EXECUTION_STATUS_RUNNING`.

What is the use case for this?

---

<div class="post-metadata">

**Author:** ![nithin](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nithin](https://community.temporal.io/u/nithin)\
**Post date:** [October 14, 2020, 7:01pm UTC](https://community.temporal.io/t/check-if-workflow-with-workflow-id-and-or-run-id-is-open/738/3 "2020-10-14T19:01:06Z")

</div>

I have an api that creates an upload for a feed (parent entity). All this API does it kick off a temporal workflow with the feed-id as the workflow-id and it uses the run-id returned by the workflow as upload-id and returns this back as the response of our api. The workflow is responsible for actually creating and persisting the actual upload entity to our database.

Now i have 2 additional read apis that i need to support

1. Get all uploads for a feed: Ideally i would have just queried our database to get this. But since the temporal workflow is the one that creates these uploads there is time gap between when i open a workflow and when the first step of the workflow executes (which creates the upload), i also need to look at temporal to get run id for an open workflow
2. Get upload with the given id(run id): again because of the time gap between when the temporal is kicked off and when the upload is created i need to query temporal to see if a workflow exists for this run id.

As I understand 1 can be done using DescribeWorkflowExecution, Is there a way i can query a workflow just by the run-id for use case 2

---

<div class="post-metadata">

**Author:** ![nithin](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nithin](https://community.temporal.io/u/nithin)\
**Post date:** [October 14, 2020, 11:25pm UTC](https://community.temporal.io/t/check-if-workflow-with-workflow-id-and-or-run-id-is-open/738/4 "2020-10-14T23:25:52Z")

</div>

@maxim is there any way to check if there is a workflow open given just the run-id (no workflow-id) ?

---

<div class="post-metadata">

**Author:** ![Pritam\_Kumar2](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pritam_kumar2/32/1342_2.png) [@Pritam\_Kumar2](https://community.temporal.io/u/Pritam_Kumar2)\
**Post date:** [September 24, 2021, 6:03am UTC](https://community.temporal.io/t/check-if-workflow-with-workflow-id-and-or-run-id-is-open/738/5 "2021-09-24T06:03:57Z")

</div>

@maxim  
cannot we use “ListWorkflowExecutionsRequest” with the query for getting running workflow with workflow id.  
I used this quer = “WorkflowType = ‘subscription.new’ and ExecutionStatus=”  
+ WorkflowExecutionStatus.WORKFLOW\_EXECUTION\_STATUS\_RUNNING\_VALUE  
and I got all the running workflows and then i checked for my workflow id. But if I have many open workflows then this will be huge list and iterating over that would be costly. So i am wondering if a can query by woekflowId to get the exact workflow and if there are none I do not want to get a exception.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [September 24, 2021, 1:31pm UTC](https://community.temporal.io/t/check-if-workflow-with-workflow-id-and-or-run-id-is-open/738/7 "2021-09-24T13:31:20Z")

</div>

You can use WorkflowId, RunId, and ExecutionStatus, individually or mix/match them, for example:

```auto

WorkflowId="myId" and RunId="myRunId" and ExecutionStatus=2

```

to get all my workflows with mentioned workflow id and run id that are in the completed status

---

<div class="post-metadata">

**Author:** ![Pritam\_Kumar2](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pritam_kumar2/32/1342_2.png) [@Pritam\_Kumar2](https://community.temporal.io/u/Pritam_Kumar2)\
**Post date:** [September 24, 2021, 1:50pm UTC](https://community.temporal.io/t/check-if-workflow-with-workflow-id-and-or-run-id-is-open/738/8 "2021-09-24T13:50:04Z")

</div>

Yes @tihomir , when I tried with ExecutionStatus = Running, it worked but when I tried with executionStatus = 1, it returned me an empty list although I had one workflow with same ID running.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [September 27, 2021, 3:51am UTC](https://community.temporal.io/t/check-if-workflow-with-workflow-id-and-or-run-id-is-open/738/9 "2021-09-27T03:51:42Z")

</div>

Is that using ListWorkflowExecutionsRequest?  
Here is example with that shows the use with ExecutionStatus set to WorkflowExecutionStatus.WORKFLOW\_EXECUTION\_STATUS\_RUNNING\_VALUE which has value 1

> <https://github.com/temporalio/samples-java/blob/master/src/main/java/io/temporal/samples/listworkflows/Starter.java#L79>
