# Can I listen for a "save event"?

**URL:** <https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388>\
**Category:** Modeler\
**Created:** [June 7, 2018, 6:25am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388 "2018-06-07T06:25:42Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![steffinger](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@steffinger](https://forum.bpmn.io/u/steffinger)\
**Post date:** [June 7, 2018, 6:25am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/1 "2018-06-07T06:25:42Z")

</div>

For my Modeler plugin I have the following need:

When the user saves the diagram, I need to start a separate function, that saves some kind of comment to a separate datastore. As far as I can see, there is no eventBus listener for this or am I missing something?

Is there any way to know, when a user saves the diagram while my program is in the context of the canvas?

---

<div class="post-metadata">

**Author:** ![steffinger](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@steffinger](https://forum.bpmn.io/u/steffinger)\
**Post date:** [June 7, 2018, 9:42am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/2 "2018-06-07T09:42:34Z")

</div>

Sorry, I’m a bit sick for some time now and missed a couple of things:  
Actions like ‘save’ are not fired on the eventBus, but triggered as an [‘EditorAction’](https://github.com/bpmn-io/diagram-js/blob/master/lib/features/editor-actions/EditorActions.js). I should have known that. And as I understand it, I could register an additional listener for an existing action like this:

```auto
function PQCParser(editorActions, eventBus, elementRegistry, databaseUtil){
  editorActions.register({
    save: function(){
      console.log("An additional listener for the save action");
    }
  });
};

```

But this does not work for the ‘save’ action, because ‘editorActions’ does not have access a lot of the camunda modeler listeners.

Is there another way to do this?

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [June 8, 2018, 11:48am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/3 "2018-06-08T11:48:14Z")

</div>

> But this does not work for the ‘save’ action, because ‘editorActions’ does not have access a lot of the camunda modeler listeners.

The Camunda Modeler handles the `save` action itself. The action never actually reaches the bpmn-js instance. This leaves you with no way to hook into `save`.

Just to clarify: Exporting XML in bpmn-js and saving the tab (persisting the XML to disk) are two different things. When exactly would you like to save additional data? On every XML export or on every persist operation?

---

<div class="post-metadata">

**Author:** ![steffinger](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@steffinger](https://forum.bpmn.io/u/steffinger)\
**Post date:** [June 8, 2018, 3:39pm UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/4 "2018-06-08T15:39:26Z")

</div>

> [@nikku](#):
>
> When exactly would you like to save additional data? On every XML export or on every persist operation?

Thanks for this very good question. I thought, the straight forward thing would be, to save my ‘comments’ every time a user saves his work, so the user experience is not broken. And I thought, the best way to achieve this would be to hook into the save action itself.

Am I understanding this correctly that for every save action a bpmn-js export is triggered? It would be totally fine to hook into the XML export then. If this was possible, could you point me at how to do this?

---

<div class="post-metadata">

**Author:** ![philippfromme](https://forum.bpmn.io/user_avatar/forum.bpmn.io/philippfromme/32/2803_2.png) [@philippfromme](https://forum.bpmn.io/u/philippfromme)\
**Post date:** [June 11, 2018, 9:07am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/5 "2018-06-11T09:07:22Z")

</div>

Right now there is no way to hook into saving the XML. It doesn’t fire any events you could listen for. The only way I see right now is wrapping the `saveXML` method and doing you magic inbetween. This is very hacky, though.

I’ve created an [issue](https://github.com/bpmn-io/bpmn-js/issues/811) for that since I see no reason why you shouldn’t be able to hook into export.

---

<div class="post-metadata">

**Author:** ![steffinger](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@steffinger](https://forum.bpmn.io/u/steffinger)\
**Post date:** [June 11, 2018, 11:10am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/6 "2018-06-11T11:10:45Z")

</div>

Thank you. That would really help me.

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [June 12, 2018, 8:28am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/7 "2018-06-12T08:28:45Z")

</div>

> [@steffinger](#):
>
> That would really help me.

I’m not quite sure that would help you. What you need is to hook into the tab saving mechanism of the Camunda Modeler. We’re going to implement it anyway, as it is a valuable addition to the toolkit.

---

<div class="post-metadata">

**Author:** ![steffinger](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@steffinger](https://forum.bpmn.io/u/steffinger)\
**Post date:** [June 12, 2018, 10:26am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/8 "2018-06-12T10:26:11Z")

</div>

> [@nikku](#):
>
> I’m not quite sure that would help you. What you need is to hook into the tab saving mechanism of the Camunda Modeler. We’re going to implement it anyway, as it is a valuable addition to the toolkit.

Oh. I thought the saving mechanism the Camunda Modeler would simply trigger the Viewer.prototype.saveXML function of bpmn-js. So this seems not to be the case. (I tried it just now with your new patch, to better understand it.)

So do you see any way to promote the save action to the bpmn-js instance, or is there a reason why these things must be separated?

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [June 12, 2018, 11:11am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/9 "2018-06-12T11:11:06Z")

</div>

The Camunda Modeler retrieves the XML representation via `BpmnViewer#saveXML` for a number of reasons, including:

- to show the correct XML in the XML tab
- saving the XML to disk because the user triggered _save_

We’d need a way to expose Camunda Modeler events to plug-in authors to really satisfy your use case.

---

<div class="post-metadata">

**Author:** ![steffinger](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@steffinger](https://forum.bpmn.io/u/steffinger)\
**Post date:** [June 12, 2018, 11:15am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/10 "2018-06-12T11:15:51Z")

</div>

> [@nikku](#):
>
> We’d need a way to expose Camunda Modeler events to plug-in authors to really satisfy your use case.

Is this something that could happen if I open a feature request and ask very kindly (or implement it myself sometime) or are there strong reasons for not exposing Camunda Modeler events?

---

<div class="post-metadata">

**Author:** ![steffinger](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@steffinger](https://forum.bpmn.io/u/steffinger)\
**Post date:** [June 12, 2018, 11:20am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/11 "2018-06-12T11:20:57Z")

</div>

To clarify: My prototype can work without this and it’s not something totally urgent. But I would need to know if this was possible.  
Maybe you could even say how much work you think this would be.

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [June 12, 2018, 11:25am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/12 "2018-06-12T11:25:04Z")

</div>

> [@steffinger](#):
>
> Maybe you could even say how much work you think this would be.

You could implement this feature and send it to us as a PR. This would surely help us to better understand what we need. We cannot promise that we ship this as an official feature any time soon, a PR may speed up things though.

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [June 12, 2018, 11:28am UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/13 "2018-06-12T11:28:00Z")

</div>

> <https://github.com/camunda/camunda-modeler/issues/828>

---

<div class="post-metadata">

**Author:** ![steffinger](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@steffinger](https://forum.bpmn.io/u/steffinger)\
**Post date:** [June 12, 2018, 12:09pm UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/14 "2018-06-12T12:09:42Z")

</div>

Thanks for opening the issue. I understand, that this is not a priority, but I’m glad, that it is possible to do. I try to make a PR as soon as I can. (Might be a month though.)

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [July 22, 2025, 3:13pm UTC](https://forum.bpmn.io/t/can-i-listen-for-a-save-event/2388/15 "2025-07-22T15:13:55Z")

</div>

Closed on July 22, 2025, 3:13pm UTC


