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) {
				setTimeout(function(e){
					var json = e.model.toIncrementalJSON(e);
			  		console.log(json);
				},1000);
			  
			}
		  });

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.

NB:
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) {
			setTimeout("save("+e+")",500);
		}
	});
    function save(e) {
		var json = myDiagram.model.toIncrementalJSON(e);
		console.log(json);
      	myDiagram.isModified = false;
    }

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

VM1393:1 Uncaught SyntaxError: Unexpected token '*'

Model | GoJS API 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. GoJS - Synergy Codes

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 Model | GoJS API

Consider also: Update Demo GoJS Sample