Set color connection

how is it possible to set the color of one or more connections?

I know to get the connection of task like this:
var activityShape = elementRegistry.get(‘someactivityId’);

var outgoing = activityShape.outgoing;
var incoming = activityShape.incoming;

but I don’t know how set the color.


Hi @Giuseppe_Zarbo and welcome in our forum!

This is not a trivial thing to do, because you first need the graphical SVG representation of the connection:

var outgoingGfx = elementRegistry.getGraphics(outgoing);

Then you can set attributes of the connection path. To change the color you can try this:'path').attr({stroke: 'blue'});

A more general approach (i.e. if you want one specific color for all sequence flows) would be to change the color in the BpmnRenderer. One way to do this is to add the stroke attribute for the desired elements (in this case all sequence flows) here:

1 Like

var activityShape = elementRegistry.get(‘SendTask_09dl0dt’);

var outgoing = activityShape.outgoing;
var outgoingGfx = elementRegistry.getGraphics(outgoing);‘path’).attr({stroke: ‘blue’});

Hi, may I ask is there something changed?

I can get “outgoing” which is the connection line. but when I call

var outgoingGfx = elementRegistry.getGraphics(outgoing);

outgoingGfx is undefined.

Thanks a lot

@pedesen Please kindly have a look at this post.Thanks a lot

var activityShape = elementRegistry.get(‘StartEvent_1’);

var outgoing = activityShape.outgoing;
    var outgoingGfx = elementRegistry.getGraphics(;'path').attr({stroke: 'blue'});

I have found the answer myself.

Great you found the solution yourself!

In my case, colored connections became black immediately after any action. Then, i’ve found another solution:

var a = bpmnRenderer.drawConnection;
var fixConnectionColor = function(visuals, connection){
	var res =,visuals, connection);
	var color = 'black';
		color = 'green';
	}'path').attr({stroke: color});
	return res;
bpmnRenderer.drawConnection = fixConnectionColor;
1 Like

@tujger That is an even better better solution. :thumbsup:

looks like now you have api modeling.setColor() to do this?

Yes, exactly as described in our latest release blog post.

I get the error below after using the setColor(), and when I am getting the xml of the diagram using saveXML()…

Any Idea what could be the issue? But the color on the connector is set correctly.

missing namespace information for di = Object on ModdleElement Error: no namespace uri given for prefix
at ElementSerializer.logNamespaceUsed (writer.js:468)
at ElementSerializer.nsAttributeName (writer.js:254)
at writer.js:348
at arrayEach (arrayEach.js:15)
at createForEach.js:15
at ElementSerializer.parseGenericAttributes (writer.js:339)
at (writer.js:210)
at writer.js:405
at arrayEach (arrayEach.js:15)
at createForEach.js:15

Make sure you use the latest bpmn-moddle.

I have applied the patches related to that…that makes it possible to save the color on connector… and also the getXML has that color set and loading again works… but still I have that in the console the error message when the setColor is invoked?