Uncaught Error: cannot create custom:task extending <bpmn:Task>

I am trying to create a custom task called so that it can be saved in the XML file as
aws:AwsTask
but I am getting the following error
Uncaught Error: cannot create <aws:AwsTask> extending <bpmn:Task>

what I did to reach this issue is
first, I modified the ReplaceOptions.js file and added the following

   {
      label: 'Aws task',
      actionName: 'replace-with-Aws-task',
      className: 'bpmn-icon-script',
      target: {
        type: 'aws:AwsTask'
      }
    },

then I modifed BPMNRenderer.js file and added the following code

  'aws:AwsTask': function(parentGfx, element, attrs = {}) {
      attrs = pickAttrs(attrs, [
        'fill',
        'stroke'
      ]);

      var task = renderTask(parentGfx, element, attrs);

      var x = 15;
      var y = 12;

      var pathDataUser1 = pathMap.getScaledPath('TASK_TYPE_USER_1', {
        abspos: {
          x: x,
          y: y
        }
      });

      drawPath(parentGfx, pathDataUser1, {
        fill: getFillColor(element, defaultFillColor, attrs.fill),
        stroke: getStrokeColor(element, defaultStrokeColor, attrs.stroke),
        strokeWidth: 0.5
      });

      var pathDataUser2 = pathMap.getScaledPath('TASK_TYPE_USER_2', {
        abspos: {
          x: x,
          y: y
        }
      });

      drawPath(parentGfx, pathDataUser2, {
        fill: getFillColor(element, defaultFillColor, attrs.fill),
        stroke: getStrokeColor(element, defaultStrokeColor, attrs.stroke),
        strokeWidth: 0.5
      });

      var pathDataUser3 = pathMap.getScaledPath('TASK_TYPE_USER_3', {
        abspos: {
          x: x,
          y: y
        }
      });

      drawPath(parentGfx, pathDataUser3, {
        fill: getStrokeColor(element, defaultStrokeColor, attrs.stroke),
        stroke: getStrokeColor(element, defaultStrokeColor, attrs.stroke),
        strokeWidth: 0.5
      });

      return task;
    }

then I created a file called AwsTask.json with the following content

{
  "name": "AwsTask",
  "uri": "http://aws",
  "prefix": "aws",
  "xml": {
    "tagAlias": "lowerCase"
  },
  "types": [
    {
      "name": "AwsTask",
      "extends": [
        "bpmn:Task"
      ],
      "properties": [
        {
          "name": "suitable",
          "isAttr": true,
          "type": "Float"
        }
      ]
    },
    {
      "name": "AnalysisDetails",
      "superClass": [ "Element" ],
      "properties": [
        {
          "name": "lastChecked",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "nextCheck",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "comments",
          "isMany": true,
          "type": "Comment"
        }
      ]
    },
    {
      "name": "Comment",
      "properties": [
        {
          "name": "author",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "text",
          "isBody": true,
          "type": "String"
        }
      ]
    }
  ],
  "emumerations": [],
  "associations": []
}

finally, in the app.js file

I added the following.

import awsTaskPackage from '../resources/AwsTask.json';

.........

var bpmnModeler = new BpmnModeler({
  container: '#js-canvas',

  propertiesPanel: {
    parent: '#js-properties-panel'
  },
  additionalModules: [
    BpmnPropertiesPanelModule,
    BpmnPropertiesProviderModule,
    BpmnColorPickerModule,
  ],
  moddleExtensions: {
    awsTask:awsTaskPackage

  },

});

The new task appears when clicking the wrench icon on a normal task

image

But once clicked, I got the error mentioned before.

Thank you for your help

cheers

From what I see you want to inherit from the bpmn:Task and not extend it, so your moddle descriptor should use superClass:

    {
      "name": "AwsTask",
-      "extends": [
+     "superClass": [
        "bpmn:Task"
      ],
      "properties": [
        {
          "name": "suitable",
          "isAttr": true,
          "type": "Float"
        }
      ]
    }

See how this works correctly in the attached codesandbox: https://codesandbox.io/p/sandbox/moddle-test-xgvk9v

2 Likes

BTW note that BPMN does not allow such extensions, so if you want to be standard-compliant, you’d need to use attributes on bpmn:Task or bpmn:ExtensionElements.

2 Likes

Thanks , Now it works

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.