Add a custom rule to cancel a connection based on a source and target Ids condition

Thank you for the reply.

I feel like it’s a bit hard to explain but I’ll try my best:
Since I’m trying to allow only “Directed acyclic graph” I’m trying to restrict the creation of connections to follow the rules of such a graph.
For example with this following diagram:
image
Tasks 1 and 2 are what I would call level 1 tasks because they are targets of the start element,
Tasks 3 and 4 are then level 2 tasks because they are targets of level 1 tasks.
And so on…

Now the rule that I’m trying to add is to prevent adding any connection from a level x element(or task) to a level y element where y<=x , like in this picture (marked red are the ones that are invalid) so the diagram’s global direction goes in one way only.
image
The way I was hoping to do this is to add a custom rule when I I try to add a connection that gives me the source and target ids and get all the connections from my xml (which will tell me what level each task is) since I figured I could use this to get all the current connections created (the only way I know how to):

try {
      const result = await this.bpmnJS.saveXML();
      const { xml } = result;
      let domparser = this.domparser.parseFromString(xml, 'text/xml');
      let elements= domparser.getElementsByTagName('bpmn:sequenceFlow');//all connections
    } catch (err) {
      console.log(err);
    }

And then once I have all the connections that are already created, alongside the source and target Ids of the connection I’m trying to create that I’m getting from the customrule I can check whether the connection is valid, and if it’s not valid, the connection shouldnt be allowed therefore canceled.

That is why I said “If I’m able to get the xml representation inside the customrulesprovider I guess that could do it as well” it’s basically just to get all the connections already created in the diagram (their sources and targets).

I hope I was somewhat clear.