Add users to roles programatically

Hi; I’m working on a function in my custom module to (dynamically) identify a user’s Active Directory groups, and based on those, to add them to specific groups in SuiteCRM. Is there a native class method to be able to do this or would I have to manipulate it by using SQL queries?

Found it I think… I assume I can use the Role->set_user_relationship($role_id, $user_ids) method on creating a $role = new Role();

This ^^ NOT working. Still stuck with how to extract a list of users belonging to a role, and also a list of roles to which a user belongs. I would have thought that something as basic as these would have been standard class/bean methods - obviously not.