Posted on 22/05/2023 11:56:11
I am not sure I follow.
In the notification, you get the newly created group. In your first code example you try to retrieve that same group from the GroupService - which makes no sense since you already have that object.
When the group is created, it has no relations yet - so after group has been created and saved to database, you only have a group - there are no relations (parents or children). If you are using the UI, the group is first created and saved to database, then the notification is fired, and then just after, the relation is created. The relation needs to group first, so the group is saved first.
When the relation is created there is another notification - Notifications.Ecommerce.Group.RelationUpdated - that will hold the ID of the group and its new parent. So maybe you need to listen for that - and make sure that it is a new group and not just an update from an existing group.
A solution could be in your groupsaved notification to save the groupid into request.items if the group is new, and then in the RelationUpdated notification react if .Items contains the groupid that the relation is created for.
Alternatively please specifiy what you are trying to do - there might be another way.
BR Nicolai