# Creating Workitem and Selecting WorkItem Queue Dynamically

**URL:** <https://discourse.openiap.io/t/creating-workitem-and-selecting-workitem-queue-dynamically/1729>\
**Category:** OpenCore\
**Created:** [August 8, 2024, 11:06am UTC](https://discourse.openiap.io/t/creating-workitem-and-selecting-workitem-queue-dynamically/1729 "2024-08-08T11:06:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gabriel\_Artiola](https://discourse.openiap.io/letter_avatar_proxy/v4/letter/g/47e85d/32.png) [@Gabriel\_Artiola](https://discourse.openiap.io/u/Gabriel_Artiola)\
**Post date:** [August 8, 2024, 11:06am UTC](https://discourse.openiap.io/t/creating-workitem-and-selecting-workitem-queue-dynamically/1729/1 "2024-08-08T11:06:38Z")

</div>

Is there a way to create a workitem and select workitem queue dynamically in nodered? I am planning to use the value from the payload, something like this **msg.payload.workitemqueue**

---

<div class="post-metadata">

**Author:** ![Allan\_Zimmermann](https://discourse.openiap.io/user_avatar/discourse.openiap.io/allan_zimmermann/32/12_2.png) [@Allan\_Zimmermann](https://discourse.openiap.io/u/Allan_Zimmermann)\
**Post date:** [August 8, 2024, 11:38am UTC](https://discourse.openiap.io/t/creating-workitem-and-selecting-workitem-queue-dynamically/1729/2 "2024-08-08T11:38:22Z")

</div>

there is no way to **create** a workitem queue from nodered ( well, there is, but you should never do that )

I strongly feel, there is no good argument for having the option to dynamically select the queue, in “pop workitem”. The whole point of queues is to separate code/logic for each queue, so popping different queues from the same code, is massively conflicting with the intention of the system.  
**IF** you need different routes the most common way is to read a value from the payload and use a switch node to fork out depending on that.

Anyway, if this is what you truly need, you can install the openiap npm package on a function node, then signin using the inherited environment variables and then call popworkitem. This **will** be slow and put a massive overhead on openflow.  
So a **much** better solution is to create a package in nodejs/python and run it inside an agent ( example [here](https://github.com/openiap/nodeworkitemagent) ) this will allow you to keep an existing connection and pop multiple queues as dynamic as you need/want.

---

<div class="post-metadata">

**Author:** ![Gabriel\_Artiola](https://discourse.openiap.io/letter_avatar_proxy/v4/letter/g/47e85d/32.png) [@Gabriel\_Artiola](https://discourse.openiap.io/u/Gabriel_Artiola)\
**Post date:** [August 8, 2024, 12:19pm UTC](https://discourse.openiap.io/t/creating-workitem-and-selecting-workitem-queue-dynamically/1729/3 "2024-08-08T12:19:41Z")

</div>

Switch node solved it. Thank you Allan. and thank you for being so responsive as always

---

<div class="post-metadata">

**Author:** ![system](https://discourse.openiap.io/uploads/default/original/2X/a/a1ca7b164ac9a826839704d9ac82c7b5e6bcf557.png) [@system](https://discourse.openiap.io/u/system)\
**Post date:** [August 11, 2024, 12:20pm UTC](https://discourse.openiap.io/t/creating-workitem-and-selecting-workitem-queue-dynamically/1729/4 "2024-08-11T12:20:02Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
