Custom Replace Action

I am trying to create a custom replace action which switches a UserTask to a ServiceTask. In the process the action should conditionally remove certain custom extension elements from the task while keeping others.

Scenario: A UserTask has a name and a documentation and it also has 3 custom extension elements “magic:spell1”, “magic:spell2”, “magic:spell3”. When clicking on the replace icon in the context pad and then choosing the custom entry “ServiceTask” the type of the element should change from UserTask to ServiceTask while the name and documentation should be kept as they are. And addtionally only the extention elements “magic:spell2” and “magic:spell3” should be kept while we want to discard “magic:spell1”.

This is the CustomReplacePadProvider I am working on. But it is missing the functionality for manipulating the extension elements.

export default class CustomReplacePadProvider {
  constructor(modeling, popupMenu, moddle, bpmnFactory, bpmnReplace) {
    this.modeling = modeling;
    this.moddle = moddle;
    this.replace = bpmnReplace;

    popupMenu.registerProvider('bpmn-replace', this);

  getPopupMenuEntries(element) {
    if (!is(element, 'bpmn:UserTask')) {

    return {
      'entry-1': {
        className: 'bpmn-icon-service-task',
        label: 'Service Task',
        action: () => {
          // define action to change type of task from UserTask to ServiceTask

  replaceUserTaskWithServiceTask(element) {
    const businessObject = getBusinessObject(element);
    const label = getLabel(element);

    // Replace UserTask with ServiceTask
    const serviceTaskProps = {
      type: 'bpmn:ServiceTask'

    const newElement = this.replace.replaceElement(element, serviceTaskProps);

    // Update the label / name
    this.modeling.updateLabel(newElement, label);
    // Update the documentation
    this.modeling.updateProperties(newElement, {
      documentation: businessObject.documentation

CustomReplacePadProvider.$inject = ['modeling', 'popupMenu', 'moddle', 'bpmnFactory', 'replace'];