It looks like the meta value’s already saved after the first step, and your group already has an ID; so it’s just a question of retrieving that. bp_get_group_id() somehow does not do the job for I don’t know what reason (maybe the group is not yet visible, or the cache has not been updated yet).