// add a virtual element (not being drawn)
element = this._elementFactory.createRoot(elementData(semantic));
this._canvas.setRootElement(element, **true** );
Hey guys,
While building a test case to show what our problem is, I saw the mistake in our code.
Because of splitting our code into modules the importXML method is in a completely other module then the calls of the getRootElement methods or the accesses to the diagram elements. In our case, the diagram wasn't completely imported before the first time another module tried to get the rootElement.
But because of the modularity of our probject we were not able to put all the following code into this one callback of the importXML method. This would have crashed our entire architecture.
So today I found out, that there is an "import.done" event on which we can listen and wait for to ensure, that all elements are available when trying to get them. Is it recommendable to use this event? Or would you advise against listening on this event (maybe because it should be an internal used event only)? An alternative could maybe be to refactor the importXML function as an async function so we can await the result?
And a question about the events: Do you have any documentations where we can read about all or at least the most relevant / useful events thrown by the bpmn-js lib? I think this would be veeeery very helpful (not only for us)!!! :) 👍
So thank you for your help and time! I hope you can give us a few tips about best practices for this case :)
Greetings,
For what it's worth I was able to reproduce this error by creating the modeler and then trying to drag an item from the palette to the canvas before the call to "importXML" is made. When you try to drag an item from the palette to the canvas the canvas turns a light shade of red indicating that it is not allowed. The error occurs when you then try to load a BPMN document by making the call to "importXML".
The error occurs due to the fact that you got a raise condition between importing (to setup the diagram) and your first modeling interaction.
As a best practice, ensure you always show a diagram, e.g. by importing an EMPTY xml file.
Makes sense. I only encountered the error while testing edge cases. I'm pulling the diagram XML from a backend data source and wanted to see the behavior if the call to retrieve the XML didn't succeed (and subsequently the importXML
function never being called). Instead of loading an empty XML file I decided to hide the palette (CSS) until the call to importXML
completed properly.
Hi all,I am facing the same issue of Error: rootElement already set, need to specify override. well in my case i want to import an bpmn/xml file first and then add the custom elements with the xml file.This part is important for my case.As my project majorly revolves around custom-elements and interaction with xml file.
Right now the fix can be of just changing the if condition in canvas.Js but i personally think this is not the right way.Kindly any update on this is highly appreciated
thanks
@AbdurRehman91 Please raise your matter in our forum. Clearly describe your use-case and what you'd like to achieve. Underline your description with examples that help us understand your case and we may be able to provide assistance.
The check is there to avoid programming / library usage errors and I presume there is a proper way to implement what you'd like to achieve without monkey patching the library.