Getting current tab(flow) id from sidebar

Hi,

Can I get the id of the opened tab (which is already deployed) from a sidebar? I am getting the flow description using flows/ endpoint but I want current flow id to filter the response from the flows/ API call. I thought using editor events and tried workspace: change. But it provides only the older tab id but not the current tab id. Is there any way to get the current tab id from my sidebar html?

Regards,
Malintha

Hi,

the payload of the workspace:change event has two properties - the old workspace you were on and the new workspace you've switched to:

{
    old: oldWorkspaceId,
    workspace: newWorkspaceId
}

But there's no need to track that yourself. You can get the id of the current workspace tab by calling:

  var activeWorkspaceId = RED.workspaces.active();

Once you have that id, it might be a subflow tab or a flow tab. To check which it is, you can do:

  var activeWorkspaceId = RED.workspaces.active();
  var flow = RED.nodes.workspace(activeWorkspaceId);
  if (!flow) {
    // this is probably a subflow
    flow = RED.nodes.subflow(activeWorkspaceId);
  }

Once you have that flow object you have access to all its properties - such as flow.info for its description. There's no need to use the /flow api to get this information.

2 Likes

Ok, one later later...
i would like to get the name of the current flow.
so with the above i tried this below

var activeWorkspaceId = RED.workspaces.active();
msg.payload = activeWorkspaceId;
return msg;

but that gives the error

"TypeError: Cannot read property 'active' of undefined"

maybe i understand the usage wrong?

1 Like

Where are you trying to do that? In a custom node or a Function node? If the latter, it doesn't have access to these APIs.

in the function node.
Is there another way to get it?

Thanks!

Nodes are supposed to be black boxes so have no concept of where they are.

Did you fand solution for this?

no sorry. I did not find a solution that worked