How to get group data after creation

How to get group data after creating using myDiagram.commandHandler.groupSelection();
We are using
var data = myDiagram.model.findNodeDataForKey(6);
We are getting null value.
After rendering from DB when we call var data = myDiagram.model.findNodeDataForKey(6), then it returns value.

It should be selected afterwards.

Or implement the “SelectionGrouped” DiagramEvent. GoJS Events -- Northwoods Software

We want to change group data without selecting the Group.
It is working when we render from DB and show in diagram.
But when we create group using myDiagram.commandHandler.groupSelection().
we can not get myDiagram.model.findNodeDataForKey(6) and for this we can not set data fro that group.

That command always selects the new Group.

How to get new group data by key?
Is there function for this?
To update group data any time after many other operations also.

After the call to CommandHandler.groupSelection, myDiagram.selection.first().data.

I get the data like you said, this function work only after group creation.
But we want to change group data any time.
Like, after creation group , we perform drag & drop a node… If then we want to change group data by key.
are you understand my problem?

You can either keep the reference to the group data object and call Model.set in a transaction, or you can keep its key and call Model.findNodeDataForKey and then call Model.set.

I am not understand.
Can you give me an example.
After creating a group using myDiagram.commandHandler.groupSelection().
Set node data by key in an example.

function test() {
  var diag = myDiagram;
  if (!diag.commandHandler.canGroupSelection()) return;

  // if you really want the key of the new group:
  // var key = diag.selection.first().key;
  // var data = diag.model.findNodeDataForKey(key);

  // this example just modifies a property in the model:
  var data = diag.selection.first().data;
  diag.model.commit(function(m) {
    m.set(data, "created",;
  }, "timestamp creation of group");

We need group data change function separately.
function groupDataChange(key,field_name,field_value){
** var data = myDiagram.model.findNodeDataForKey(key);**
** myDiagram.model.setDataProperty(data, field_name, field_value);**

Your code looks good, assuming you call it, perhaps repeatedly, within a transaction.

To format all of the code, use separate lines consisting of three backquotes both before and after the code.

we are calling it out side group creation function.
It is returning null.
But when we fetch data from DB and show group in diagram then this function is working fine.
It is only happening on a new group before save.

Well, maybe you are using the wrong key. Are you sure you are using the same key as it was given when it was created? Maybe you change the key on the database side?

Thanks a lot.