Insert temporary link into diagram

Hello,

I would like to insert a temporary link between two nodes programmatically, i.e. the link should be visible, but not be added to the model and not be included in the undo manager.
The temporary link will be removed programmatically triggered by a user action, or at latest when our app is closed (as the link is not persisted in the model).
Background is that we want to suggest the user to add a link between two nodes, and the user can accept or discard the suggestion.

How can I add a link (temporarily) to the diagram but not to the model?
I tried to add it to a temporary layer, but I couldn’t find an option to specify the layer in LinkingTool.insertLink(). Also, I am not sure if it will work if the link is in another layer than it’s connected nodes?
What would be the best way to do this?

Just create a Link and call Diagram.add with it, in a transaction where skipsUndoManager is temporarily true.

  function test() {
    var source = myDiagram.findNodeForKey(1);
    var destination = myDiagram.selection.first();
    if (source !== null && destination instanceof go.Node) {
      myDiagram.commit(function(diag) {
        var $ = go.GraphObject.make;
        var unmodeled =  // or just diag.linkTemplate.copy()
          $(go.Link,
            { layerName: "Foreground", curve: go.Link.Bezier },
            $(go.Shape, { stroke: "red", strokeDashArray: [8, 4] }),
            $(go.Shape, { toArrow: "Standard", fill: "red", strokeWidth: 0 })
          );
        unmodeled.fromNode = source;
        unmodeled.toNode = destination;
        diag.add(unmodeled);
      }, null);  // null means skipsUndoManager
    }
  }

I should caution you that you might not like some of the effects of using skipsUndoManager, when undoing to the time when you added the temporary link(s), or when deleting a temporary link. You’ll need to experiment with it to get the effects that you want.

Ah perfect, thanks!