GoJS and collaboration

Hi, I try to develop an application in which a number of users can collaborate on designing a flowchart. I took the code from the example and I added a listerner for changes to the diagram so I can send changes to a server. The code I use (after reading various documents):

myDiagram.addModelChangedListener(function(e) {
			if (e.isTransactionFinished) {
					var json = e.model.toIncrementalJSON(e);

The timeout function is added so the tiIncrementalJSON is called well after the page is loaded. I get an error: “cannot read property model of undefined”…
Can anybody show me the right way to get changes to the diagram?
Thank you.

If I delete the timeout, and use the function as depicted in the document on this site, I get an error on pageload:

go.js:12 Uncaught Error: GraphLinksModel.linkKeyProperty must not be an empty string for .toIncrementalJson() to succeed.
    at B (go.js:12)
    at or.t.Vw (go.js:1839)
    at or.t.Vy (go.js:1772)
    at or.t.aB (go.js:1772)
    at flowdiagram.php:52
    at or.t.zt (go.js:1785)
    at Ae.Bb (go.js:268)
    at Be (go.js:265)
    at Ae.t.Wa (go.js:263)
    at Q.Wa (go.js:692)

so I added the timeout.

Update: I changed the code to this:

    myDiagram.addDiagramListener("Modified", function(e) {
		if (myDiagram.isModified) {
    function save(e) {
		var json = myDiagram.model.toIncrementalJSON(e);
      	myDiagram.isModified = false;

Now I get the error (when diagram is modified):

VM1393:1 Uncaught SyntaxError: Unexpected token '*'

https://gojs.net/latest/api/symbols/Model.html#toIncrementalJson needs to be passed the “Transaction” ChangedEvent passed to your ModelChanged listener. The function called by setTimeout will not be called with arguments.

And in your following post, you really should not be trying to evaluate a string as code, particularly when it is not possible to pass the ChangedEvent by trying to convert it to a string and back again.

It will be difficult for you to implement collaboration. You might want to look at the solution that Synergy Codes provides. https://synergycodes.com/gojs/

Thank you for the answer.
I tried several code-snippets, none seems to work.
Is it not possible to get the JSON string from the last added / modified object?

Example is at https://gojs.net/latest/api/symbols/Model.html#toIncrementalJson

Consider also: https://gojs.net/latest/samples/updateDemo.html