How to add a label to a connection?

Hi

Very new to bpmn-js and wanting to use it to display a workflow to users with limited editing capabilities.

I’m at the stage of programmatically building a diagram from my own object model. I’m finding it extremely difficult to find documentation on how to do things!

Anyway, first question - I use the modeling.connect function to connect a bpmn:Task to a bpmn:ExclusiveGateway but how do I add a custom label to the connection?

I’ve a tonne more questions, but I’ll make them separate posts so as to keep things focused.

Thanks…

Thanks for your feedback. We’re always happy to hear topics for possible developer documentation, so that we might improve the situation in the (near) future. Feel free to name certain things (maybe in another thread) so we can bring this into our plans.

1 Like

The name has to be given by the business object of the to be created connection.

const businessObject = bpmnFactory.create("bpmn:SequenceFlow", {
  name: "my connection"
});

modeling.createConnection(
  startEvent,
  task,
  {
    type: "bpmn:SequenceFlow",
    businessObject: businessObject
  },
  startEvent.parent
);

See this CodeSandbox for more details.

1 Like

Thanks Niklas - I have that working now - at least adding labels to the connections.

Is there a place that I can find developer documentation on what is possible, or do I have to either read the source code or ask forum questions? I’ve had a look at the example repos but they’re of limited use unless they cover the scenario I’m wanting to implement.

Currently, there isn’t detailed documentation, unfortunately. So looking at the source code, understand the core concepts and search for help in the forum will be the best way to do.

1 Like

Small suggestion…we also needed a label for sequence flow but we replaced it with a tool tip. Like when user places mouse on sequence flow, a tooltip will popup.

To achieve this, add a extension element to sequence flow with the label you want to display,
write a event listener for mouseover, and then get the extension element body to display as a tool tip

I hope you like my idea, if not ignore it please.