Get querystring from Node Red Dashboard URL

We're trying to pick up a query-string parameter from a node red dashboard URL so that on load we can fetch some relevant information from other API's.

for instance NR DB url is


we want to strip out the mcID=H01.

In JS we would normally use either

let params = (new URL(document.location)).searchParams;
let name = params.get("mcID")

or more basic

var mcid='';   
var url = window.location.href
    .slice(window.location.href.indexOf("?") + 1)

  for (var i = 0; i < url.length; i++) {
    var urlparam = url[i].split("=");
    if (urlparam[0] == 'mcID') {
      mcid= urlparam[1];

Any suggestions?


var url = window.location.href
var params =  new URLSearchParams("?" + url.split("?")[1])
var mcID = params.get("mcID")
this.scope.send({payload: mcID});

example flow

[{"id":"70df2e550e8e6350","type":"debug","z":"743cc0234f1851f1","name":"debug 387","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":240,"wires":[]},{"id":"09a2781b78b92080","type":"ui_template","z":"743cc0234f1851f1","group":"2d4fe667.28f8ba","name":"","order":15,"width":0,"height":0,"format":"<script>\nvar url = window.location.href\nvar params =  new URLSearchParams(\"?\" + url.split(\"?\")[1])\nvar mcID = params.get(\"mcID\")\nthis.scope.send({payload: mcID});\n</script>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","className":"","x":560,"y":240,"wires":[["70df2e550e8e6350"]]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":2,"disp":true,"width":"18","collapse":false,"className":""},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

Works perfectly, Thank you

I think this should work to

    var url = window.location.href;
    var params = new URLSearchParams(url);
    var mcID = params.get("mcID");
    this.scope.send({payload: mcID});

so that on load we can fetch some relevant information from other API's.

Just a side-note - the ui-control node provides the url parameters, so in case you want to use it for API calls in other nodes, it is already available.

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