findLinkForKey is returning null for first time and on reload is working fine

Hi all,

We are trying to change a link parameter on some user action. We are trying to do it by finding the link first and then updating the parameter for it and are using findLinkForKey. However, we noticed that even though the link is existing this method is returning null which is why our parameter update is failing. On page reload, this is not happening. Can someone suggest why this would happen.

Attaching a screenshot for the same.

I’m guessing that there are some code paths in which GraphLinksModel.linkKeyProperty is not set to “key”: GraphLinksModel | GoJS API

Hi @walter linkKeyProperty is being set to “key” but still we are getting null when tried findLinkForKey. Anything else we are missing here ?

How and when did that link data object get that value for the “key” property?

Hi @walter,

We are updating the key on an event dispatch. This event dispatch occurs when the link is drawn, and we configure this mapping in the diagram configuration. We catch the event in the linkDrawn method. However, in this method, the diagram provides us with the default key (i.e., -1). Subsequently, we attempt to update the key (our generated key) in the linkData object.

Afterwards, we call the method setEdgeDetails. Within this method, we invoke diagram.model.commit to update the details. We have also attempted to update the key here. However, none of the above steps seem to work.

We can observe that the key is updated in the diagram object. However, when we perform findLinkForKey on the diagram, it returns null. Additionally, when we use the default key (-1), it returns the link details.

Could you please review our approach and see if we are missing something here? Specifically, is there anything we need to consider to ensure that findLinkForKey returns the updated link details correctly?


To change the key, you cannot just modify that data property. Call GraphLinksModel.setKeyForLinkData