Getting current tab(flow) id from sidebar

#1

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

0 Likes

#2

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