Get key before adding shape

Hi. It is possible to get the key of the object before adding it to diagram. I am using clickCreatingTool to add shape on diagram. I want to get the key first before adding it to the diagram

I assume you are asking about how to specify the automatic assignment of node data keys in the model.

You just need to supply a function as the value of your model’s property.

Can you give me an example on how to use that

Here are two samples that make use of makeUniqueKeyFunction:

An extra example, showing how to make sure all new node keys have values > 1000000:

    function bigUniqueId(model, data) {
      if (data.key === undefined || model.findNodeDataForKey(data.key) !== null) {
        var k = 1000000 + model.nodeDataArray.length;
        while (model.findNodeDataForKey(k) !== null) k++;
        return k;

    myDiagram.model = $(go.GraphLinksModel, {
        . . .,
        makeUniqueKeyFunction: bigUniqueId,
        nodeDataArray: ...Array...,
        linkDataArray: ...Array...

This is such a big help. Thanks for the support.