I assume that as a supervisor you mean the manager of an organizational unit? If this is the case, there is standard solution for this. Just open the step in the workflow builder and check the agent determination part. There are multiple different ways to find get the agents and one of them is for getting the supervisor (based on rule 168 and function SWX_GET_MANAGER). Try that one out. No need to code anything by yourself. (Well, you might want to do some improvements to the standard rule, but that's another story.)
Regards,
Karri