# How to correctly call OPC UA BROWSE node in a loop?

**URL:** <https://discourse.nodered.org/t/how-to-correctly-call-opc-ua-browse-node-in-a-loop/87261>\
**Category:** General\
**Tags:** function-node, opcua\
**Created:** [16 April 2024 05:46 UTC](https://discourse.nodered.org/t/how-to-correctly-call-opc-ua-browse-node-in-a-loop/87261 "2024-04-16T05:46:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![trexnickel](https://avatars.discourse-cdn.com/v4/letter/t/a88e4f/32.png) [@trexnickel](https://discourse.nodered.org/u/trexnickel)\
**Post date:** [16 April 2024 05:46 UTC](https://discourse.nodered.org/t/how-to-correctly-call-opc-ua-browse-node-in-a-loop/87261/1 "2024-04-16T05:46:26Z")

</div>

Hi,

I am learning opc ua and using node-red OPC UA nodes to create a flow where I can read all the variables periodically. After getting the complete address space of thr OPC UA server, I filtered out all the variable references in an array. In a simple for loop, I am then, calling the BROWSE node for each of these variables using node.send(msg) after setting msg.topic with the nodeId (ns=x;i=y).

The BROWSE node produces the correct payload only if single element is present in the variable array(single-element-array.jpg). Which means when its called only once. Calling more then once, the payload has no items in the array(multiple-element-array). What could be the reason the BROWSE node doesn't work when called in a loop?

Here's the flow:

```auto
[
    {
        "id": "ae2e6953005a4235",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "09131db5fbb93ca4",
        "type": "inject",
        "z": "ae2e6953005a4235",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 200,
        "y": 180,
        "wires": [
            [
                "859de096ba5b88bc"
            ]
        ]
    },
    {
        "id": "859de096ba5b88bc",
        "type": "function",
        "z": "ae2e6953005a4235",
        "name": "test_overloading",
        "func": "let variables_array = [\t\t{\n\t\t\"referenceTypeId\": \"ns=0;i=47\",\n\t\t\"isForward\": true,\n\t\t\"nodeId\": \"ns=0;i=2256\",\n\t\t\"browseName\": {\n\t\t\t\"namespaceIndex\": 0,\n\t\t\t\"name\": \"ServerStatus\"\n\t\t},\n\t\t\"displayName\": {\n\t\t\t\"text\": \"ServerStatus\"\n\t\t},\n\t\t\"nodeClass\": \"Variable\",\n\t\t\"typeDefinition\": \"ns=0;i=2138\"\n\t},\n\t{\n\t\t\"referenceTypeId\": \"ns=0;i=46\",\n\t\t\"isForward\": true,\n\t\t\"nodeId\": \"ns=0;i=2255\",\n\t\t\"browseName\": {\n\t\t\t\"namespaceIndex\": 0,\n\t\t\t\"name\": \"NamespaceArray\"\n\t\t},\n\t\t\"displayName\": {\n\t\t\t\"text\": \"NamespaceArray\"\n\t\t},\n\t\t\"nodeClass\": \"Variable\",\n\t\t\"typeDefinition\": \"ns=0;i=68\"\n\t}];\nfor (let i = 0; i < variables_array.length; i++) {\n let node_id = variables_array[i].nodeId;\n msg.payload = \"\";\n msg.topic = node_id;\n node.send(msg);\n}\nvariables_array = null;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 180,
        "wires": [
            [
                "f0e40795a880a0e7"
            ]
        ]
    },
    {
        "id": "f0e40795a880a0e7",
        "type": "OpcUa-Browser",
        "z": "ae2e6953005a4235",
        "endpoint": "d98c1a19c588c1be",
        "item": "",
        "datatype": "",
        "topic": "",
        "items": [],
        "name": "Read SIngle Node",
        "x": 610,
        "y": 180,
        "wires": [
            [
                "01323ead260f0b62"
            ]
        ]
    },
    {
        "id": "01323ead260f0b62",
        "type": "debug",
        "z": "ae2e6953005a4235",
        "name": "read_variables",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 180,
        "wires": []
    },
    {
        "id": "d98c1a19c588c1be",
        "type": "OpcUa-Endpoint",
        "endpoint": "opc.tcp://192.168.1.20:53530/OPCUA/SimulationServer",
        "secpol": "None",
        "secmode": "None",
        "none": true,
        "login": false,
        "usercert": false,
        "usercertificate": "",
        "userprivatekey": ""
    }
]

```

 ![single-element-array](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/7271e99d104b51b3c21f353af34639a711b04d3d.jpeg)  
 ![multiple-element-array](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2cb09a9efebbb3fe3d5c19a16b02601008c28abc.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 July 2024 05:46 UTC](https://discourse.nodered.org/t/how-to-correctly-call-opc-ua-browse-node-in-a-loop/87261/2 "2024-07-15T05:46:50Z")

</div>

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