Error Lock Task Connection with Exclusive Gateway

Good morning, sorry for the inconvenience. I have a little issue with setting rules in the pre-packaged plugin. The thing is, I want to set up a rule so that when a task is created and a connection is established, it shouldn’t be able to connect to an existing exclusive gateway. The problem is that when I set the parameters, this happens. How could I fix it?

2024-11-11 09-46-56

Here is my rules code.

class CustomRules {
    constructor(eventBus) {
        eventBus.on([
          'commandStack.shape.create.canExecute'
        ], 10000, ({ context }) => {
          const { target, shape } = context;

          if (target.type === 'bpmn:SequenceFlow') {
            // disallow inserting into flow
            return false;
          }

          if (shape && target && shape.id === target.id) {

            return false;
          }
        });

        eventBus.on([
            'commandStack.elements.move.canExecute'
          ], 10000, ({ context }) => {
            const { shapes, target } = context;
console.log(shapes[0].type);

if (shapes[0].type === 'bpmn:BusinessRuleTask' || shapes[0].type === 'bpmn:ManualTask' || shapes[0].type === 'bpmn:ServiceTask') {
            // Prevent moving elements onto sequence flows
            if (target && target.type === 'bpmn:SequenceFlow') {
            return false;
            }

            // Prevent moving elements onto themselves
            if (shapes && shapes.length && target) {
            const movingOntoSelf = shapes.some(shape => shape.id === target.id);
            if (movingOntoSelf) {
                return false;
            }
            }


        }else{

            if (target && target.type === 'bpmn:SequenceFlow') {
                return false;
                }


        }
            // Allow valid movements return true;

          });

        eventBus.on([
            'commandStack.connection.reconnect.canExecute'
          ], 10000, ({ context }) => {

            const { target, source } = context;

            var connection = context.connection;

        if (connection.id.replace('Flow_', '')  !== source.id) {
              return false;
            }

            if (source && target && source.id === target.id) {
              return false;
            }

            if (target.type === 'bpmn:ExclusiveGateway') {
                return false;
                }
          });

          eventBus.on([
            'commandStack.connection.create.canExecute'
          ], 10000, ({ context }) => {

            const { target, source } = context;

            var connection = context.connection;

            if (source && target && source.id === target.id) {
              return false;
            }

            if (target.type === 'bpmn:ExclusiveGateway') {
                return false;
            }

          });


      }
     }
 CustomRules.$inject = ['eventBus'];

Have a look at the custom modeling rules example to learn how to make rules work. You can also check out the Rules Provider JSDocs: diagram-js/lib/features/rules/RuleProvider.js at develop · bpmn-io/diagram-js · GitHub

Good afternoon, greetings. Thank you very much for responding. I was reading and reviewing the documentation, but unfortunately, I haven’t been able to find the solution to this problem. That is, in a way, I achieved a pseudo-solution by making the validation return null, which has the expected effect but not in the way I want. My goal is to inform the user that pointing is not allowed and to display the denied symbol or icon when the direction points to the exclusive gateway. However, returning null does not allow placing it, but it also does not prevent positioning it over the gateway. I am currently managing BPMN.JS through the CDN.

If you want to disallow an action, your rule should return false.

Yes, I understand that, but what happens is that if I do that—meaning if I use return false—the direction gets reversed instead of being blocked. I demonstrated this in the code I showed earlier, and the reaction to using false is as shown in the GIF. If you need more tests or code from my implementation, I can provide them.

Please share a running / prototypical example that clearly shows what you’re trying to achieve, what is working and what is not.

Use our existing starter projects to quickly hack it or share your existing, partial solution on GitHub or via a CodeSandbox. Provide the necessary pointers that allow us to quickly understand where you got stuck.

This way we may be able to help you in a constructive manner.

Thanks :heart:

Ok, thank you very much for your advice. Throughout today, I will upload my project and share the details of my situation with the rule validations.

Good morning, sorry for the delay. Here is the link to a demo with the implementation of the rules. Apologies for the wait; the reason it took a bit longer is because I had to request permission to adapt this into a demo, and I had to change the structure in order to make it public. But here is the link to the demonstration. The issue is as follows: Task 1 has an exclusive gateway that leads to Task 3, but I also want to validate that Task 2 cannot use the same gateway as Task 1. However, when I try to validate this so that it shows ‘denied,’ it reverses, and now the gateway points to Task 2, even though I assigned return false.

https://codesandbox.io/p/sandbox/yqw88f

Good morning, is there a possibility to resolve this issue? I would prefer that the matter not be closed.

In your rules, you check for target type:

if (target.type === "bpmn:ExclusiveGateway") {
  return false;
}

When a connection is reversed, it’s actually the source which you need to check. In such case, you will have to do some additional checks to actually allow the connection in the valid cases.

Have a look at a similar post: How to config only one flow between two elements?