It sounds like you might want to use a reference set selector. In this selector you can display all the departments the user can choose from. If they choose them from the list, a reference between them and the department is set. It's not “automatic”, but unless you have the data of which department they belong to in an external system you can call (with an API or so) it's probably your best bet.