Getting the assigned resource name on a levelled task with applescript or JXA

I have a script that I’m using to transfer data between omniplan and another system. For tasks that have a specific resource assigned I can easily get the name of that resource, however if a task is assigned a resource group and then a resource from that group is assigned during levelling, when I try and get the resource name in the script it gets the resource group name rather than the specifically assigned resource. What am I missing? How can I get the name of the assigned resource?