# Adding more than one element to the Palette

**URL:** <https://forum.bpmn.io/t/adding-more-than-one-element-to-the-palette/11071>\
**Category:** Modeler\
**Created:** [May 26, 2024, 1:24pm UTC](https://forum.bpmn.io/t/adding-more-than-one-element-to-the-palette/11071 "2024-05-26T13:24:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aws\_rayyan](https://forum.bpmn.io/user_avatar/forum.bpmn.io/aws_rayyan/32/5152_2.png) [@Aws\_rayyan](https://forum.bpmn.io/u/Aws_rayyan)\
**Post date:** [May 26, 2024, 1:24pm UTC](https://forum.bpmn.io/t/adding-more-than-one-element-to-the-palette/11071/1 "2024-05-26T13:24:42Z")

</div>

I was to add more than one element to my Palette, I can only add one. I created two CustomPalette.js files for each of the objects I want to add and imported them in my main.js, however, only the last imported element is shown in the palette

This is one of the CustomPalette.js files

```auto
export default class CustomPalette {
  constructor(create, elementFactory, palette, translate) {
    this.create = create;
    this.elementFactory = elementFactory;
    this.translate = translate;

    palette.registerProvider(this);
  }

  getPaletteEntries(element) {
    const { create, elementFactory, translate } = this;

    function createServiceTask(event) {
      const shape = elementFactory.createShape({
        type: "vyoo_action:VyooAction",
      });

      create.start(event, shape);
    }

    return {
      "create.service-task": {
        group: "activity",
        className: "bpmn-icon-service-task",
        title: translate("Create Action"),
        action: {
          dragstart: createServiceTask,
          click: createServiceTask,
        },
      },
    };
  }
}

CustomPalette.$inject = ["create", "elementFactory", "palette", "translate"];

```

The other one is the same, with different names and icons.

This is my index.js file in the custom folder.

```auto
import CustomPalette from "./CustomPalette";

export default {
  __init__ : ["customPalette"],
  customPalette: ["type", CustomPalette],
};

```

An example is as follows if my main.js has the following when creating the modeller

```auto
  additionalModules: [
    BpmnPropertiesPanelModule,
    BpmnPropertiesProviderModule,
    customVyooActionModule,
    customVyooFormModule,
  ],

```

Then customVyooFormModule is shown, but if it was

```auto
  additionalModules: [
    BpmnPropertiesPanelModule,
    BpmnPropertiesProviderModule,
    customVyooFormModule,
    customVyooActionModule,
  ],

```

then customVyooFormModule is shown

---

<div class="post-metadata">

**Author:** ![Alessia\_Volpi](https://forum.bpmn.io/user_avatar/forum.bpmn.io/alessia_volpi/32/5289_2.png) [@Alessia\_Volpi](https://forum.bpmn.io/u/Alessia_Volpi)\
**Post date:** [May 26, 2024, 5:37pm UTC](https://forum.bpmn.io/t/adding-more-than-one-element-to-the-palette/11071/2 "2024-05-26T17:37:13Z")

</div>

Try to return not just the one you added but the entire set of entries.  
You first create the entries you need  
YourExpansionName.prototype.getContextPadEntries = function(element) {  
var bpmnReplace = this.\_bpmnReplace,  
elementRegistry = this.\_elementRegistry,  
translate = this.\_translate,  
viewer = this.\_viewer,  
return function(entries) {  
entries[“new entry”]={}  
entries[“new entry”]={}  
return entries;  
}

---

<div class="post-metadata">

**Author:** ![Aws\_rayyan](https://forum.bpmn.io/user_avatar/forum.bpmn.io/aws_rayyan/32/5152_2.png) [@Aws\_rayyan](https://forum.bpmn.io/u/Aws_rayyan)\
**Post date:** [May 26, 2024, 9:07pm UTC](https://forum.bpmn.io/t/adding-more-than-one-element-to-the-palette/11071/3 "2024-05-26T21:07:57Z")

</div>

Thank you so much. That indeed worked.

For future reference, if anyone faces the same issue,  
you don’t have to create a custom palette for each element. In fact, YOU SHOULDN’T.

create a single custom palette, and use it for all the other elements,

for each element, create a function such as createServiceTask in the above code, and in the final return statement, reference these functions in their respective code.

Here is a code snippet for the demonstration

```auto
// CustomPalette.js
export default class CustomPalette {
  constructor(bpmnFactory, create, elementFactory, palette, translate) {
    this.bpmnFactory = bpmnFactory;
    this.create = create;
    this.elementFactory = elementFactory;
    this.translate = translate;

    palette.registerProvider(this);
  }

  getPaletteEntries(element) {
    const { bpmnFactory, create, elementFactory, translate } = this;

    function createTask() {
      return function (event) {
        const businessObject = bpmnFactory.create("form:cusForm");
        const shape = elementFactory.createShape({
          type: "vform:cusForm",
          businessObject,
        });

        create.start(event, shape);
      };
    }

    function createActionElements(event) {
      const shape = elementFactory.createShape({
        type: "action:cusAction",
      });

      create.start(event, shape);
    }

    return {
      "create.lindaidai-task": {
        group: "model",
        className: "icon-custom lindaidai-task",
        title: translate("awsaws aws"),
        action: {
          dragstart: createTask(),
          click: createTask(),
        },
      },
      "create.service-task": {
        group: "activity",
        className: "bpmn-icon-service-task",
        title: translate("Create Action"),
        action: {
          dragstart: createActionElements,
          click: createActionElements,
        },
      },
    };
  }
}

CustomPalette.$inject = [
  "bpmnFactory",
  "create",
  "elementFactory",
  "palette",
  "translate",
];

```

finally, reference this in your main.js, same as above

---

<div class="post-metadata">

**Author:** ![system](https://forum.bpmn.io/uploads/default/original/2X/b/b534893973385c2d302b38572464112e4adae002.png) [@system](https://forum.bpmn.io/u/system)\
**Post date:** [June 2, 2024, 9:08pm UTC](https://forum.bpmn.io/t/adding-more-than-one-element-to-the-palette/11071/4 "2024-06-02T21:08:33Z")

</div>

Closed on June 2, 2024, 9:08pm UTC

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