SelectionDeleting Event is running when i double click on link

Hello I created a SelectionDeleting Event, which is working. However when I double click on a link it says g is null. The double clicking on a link it totally seperate from the selectiondeleting function. Its as if when I call the following

var newnode = createNodeAndLink(link._dragData, fromnode, linkDataFrom, linkDataTo );

it errors out to g is null in the console. This function was working properly before I added my SelectionDeleting function. The code for the SelectionDeleting function is below: Just to reiterate SelectionDeleting function works. The createNodeAndLink works if the SelectionDeleting function is commented out.

myDiagram.selection.each(function(node) {
//general deletion of a node
if (node instanceof go.Node) {
data = node.data;
myDiagram.model.setDataProperty(data, ‘status’, ‘deleted’);
myDiagram.model.setDataProperty(data, ‘visible’, false);
console.log(myDiagram.selection.first().part);
checkGroupNode = myDiagram.selection.first().part.findNodesConnected();
console.log(checkGroupNode)
while (checkGroupNode.next()) {
if (checkGroupNode.value.data.type === “group_parent”){
myDiagram.model.setDataProperty(checkGroupNode.value.data, ‘status’, ‘deleted’);
myDiagram.model.setDataProperty(checkGroupNode.value.data, ‘visible’, false);
var partsGroup = checkGroupNode.value.memberParts;
while (partsGroup.next()){
myDiagram.model.setDataProperty(partsGroup.value.data, ‘status’, ‘deleted’);
myDiagram.model.setDataProperty(partsGroup.value.data, ‘visible’, false);
}
var linksConnectedGroup = checkGroupNode.value.findLinksConnected();
while (linksConnectedGroup.next()){
console.log(linksConnectedGroup.value.data)
savedLink = linksConnectedGroup.value;
}
}
}
}

                        //deletion of a group and its children
                         if (myDiagram.selection.first().part.data.type === 'group_parent') {
                            for (var it = myDiagram.nodes; it.next(); ) {
                                var n = it.value;  // n is now a Node or a Group
                                if (n.data.type === "link_item" && n.data.group === data.key ) { 
                                   myDiagram.model.setDataProperty(n.data, 'status', 'deleted');
                                   myDiagram.model.setDataProperty(data, 'visible', false);
                                   var it = myDiagram.selection.first().part.findLinksConnected(), i= 0;
                                   while (it.next()) {
                                       i++
                                      var item = it.value, fromNode, toNode;
                                      if (i === 1){
                                          fromNode = item.data['to'];
                                      } else if (i === 2){
                                         toNode = item.data['from'];
                                      }   
                                   }
                                   myDiagram.startTransaction("create Links");
                                   myDiagram.model.addLinkData({ from: fromNode, to: toNode });
                                   myDiagram.commitTransaction("create Links");
                                }
                            } 
                        }
                        
                        
                        //deletion of links
                        if (myDiagram.selection.first().part.data.points){
                            //console.log(myDiagram.findLinkForData(myDiagram.selection.first().part.data).data)
                            var data = myDiagram.findLinkForData(myDiagram.selection.first().part.data).data,
                                fromNode = data['from'],
                                toNodeOld = data['to'],
                                nodeOld, finalToNode;
                            if (data['group_id'] !== 'undefined'){
                                 nodeOld = myDiagram.findNodeForKey(fromNode);
                                 //console.log(nodeOld.data['key'])
                            }else{
                                 nodeOld = myDiagram.findNodeForKey(toNodeOld);
                                 //console.log(nodeOld.data['key'])
                            }
                                var it = nodeOld.findLinksOutOf(), group, toNodeNew;
                                while (it.next()){
                                    toNodeNew = it.value.data['to'];
                                    if (it.value.data['group_id']){
                                         group = myDiagram.findNodeForKey(it.value.data['from']);
                                    }else if (it.value.data['group_id'] !== 'undefined') {
                                         group = myDiagram.findNodeForKey(it.value.data['to']);
                                    }
                                }
                               
                                if (group.data.type ===  'group_parent'){
                                    //group status to deleted and visible to false
                                    myDiagram.model.setDataProperty(group.data, 'status', 'deleted');
                                    myDiagram.model.setDataProperty(group.data, 'visible', false);
                                    //nodes within group status to deleted and visible to false
                                    for (var it = myDiagram.nodes; it.next(); ) {
                                        var n = it.value;
                                        if (n.data.type === "link_item" && n.data.group === group.data.key ) {
                                            myDiagram.model.setDataProperty(n.data, 'status', 'deleted');
                                            myDiagram.model.setDataProperty(n.data, 'visible', false);
                                        }
                                    }
                                   myDiagram.startTransaction("create Links");
                                   myDiagram.model.addLinkData({ from: fromNode, to: toNodeNew });
                                   myDiagram.commitTransaction("create Links");  
                                }
                                
                            var keyGroup = group.data['key'];
                        }
                        
                        if (keyGroup){
                            //console.log(group.data['key'])
                            var itGroupInto = group.findNodesInto(), 
                                itGroupOut = group.findNodesOutOf(), 
                                fromGroupNode,
                                toGroupNode;
                             while (itGroupInto.next()){
                               fromGroupNode = itGroupInto.value.data['key']
                               //console.log(itGroupInto.value.data['key'])
                             } 
                             while (itGroupOut.next()){
                                toGroupNode = itGroupOut.value.data['key']
                               // console.log(itGroupOut.value.data['key'])
                             }
                              myDiagram.startTransaction("create Links");
                              myDiagram.model.addLinkData({ from: fromGroupNode, to: toGroupNode });
                              myDiagram.commitTransaction("create Links");  
                              myDiagram.model.setDataProperty(group.data, 'status', 'deleted');
                              myDiagram.model.setDataProperty(group.data, 'visible', false);
                              
                               for (var it = myDiagram.nodes.iterator; it.next(); ) {
                                      // console.log(it.value)
                                       if (it.value instanceof go.Node ) {
                                           if (it.value === group){
                                                savedNode = it.value;
                                            } 
                                        }
                              }
                       }  
                    });
                    if (typeof savedNode !== 'undefined'){
                        myDiagram.remove(savedNode)
                    }
                    if (typeof savedLink !== 'undefined'){
                        myDiagram.remove(savedLink)
                    }
                   // console.log(myDiagram.model.toJson())
                    e.cancel = false;
                    myDiagram.commitTransaction('change status');  
                     e.cancel = false;
                myDiagram.commitTransaction("delete");
              }

also here is where the createNodeAndLink function lives:

function clickNewNode(e, link) {
if (link.fromNode.part.data.isGroup == true || link.toNode.part.data.isGroup == true ){
return;
}
var linkDataFrom = link.part.data.from,
linkDataTo = link.part.data.to;
link._dragData = {};
link._dragData.text = ‘Related Elements’;
link._dragData.isGroup = true;
link._dragData.type = ‘group_parent’;
link._dragData.category = ‘group’;
var fromnode = link.part;
link._dragData.loc = (fromnode.location.x + -950) + ‘,’ + (fromnode.location.y + -450);
var data = link._dragData;
if (!data) return;
e.diagram.startTransaction(‘Create Node and Links’);
console.log(link._dragData, fromnode, linkDataFrom, linkDataTo)
var newnode = createNodeAndLink(link._dragData, fromnode, linkDataFrom, linkDataTo );
newnode.location = new go.Point(fromnode.location.x + 50, fromnode.location.y);
updateLinkNodeData(newnode)
e.diagram.commitTransaction(‘Create Node and Links’);
}

I’m sorry, but I’m unable to read your code.

The “SelectionDeleting” DiagramEvent is only raised by the CommandHandler.deleteSelection command.

What is it that you are trying to accomplish in that event listener? Are you sure that you need to use a “SelectionDeleting” DiagramEvent? We are deprecating that functionality in 1.7. The documentation for that DiagramEvent says that you must not modify the selection or the diagram in a listener.

In the SelectionDeleting event i am canceling the delete event and creating my own. I am doing this because I don’t want to delete any nodes, I want to make them invisible and give them a status of visible:true and status:delete. I do want to delete the links. I am not saving any data about the links.

This function is working. Its accomplishing what I want done.

I figured it out :). Can you suggest what other function to use besides the SelectionDeleting since it is being depreciated?

It sounds as if you do not really want to “delete all selected parts” – you just want to modify some of them, and maybe delete some links.

Implement your own “delete” command that does exactly what you want. No need for a DiagramEvent listener.

One way to do that is to override CommandHandler.deleteSelection. That will cause the keyboard DELETE key as well as context menus to use your new functionality. If you have some need to invoke the original behavior, you can still call CommandHandler.prototype.deleteSelection.

your correct only modify them and delete the links. I will look at the commandhandler.deleteSelection. Thank you!