From your comment I think that you are on the right track. One thing you need to make sure is that you put your code at the bottom of the page and make sure mx is loaded before calling mx.ui.getProfile
Luckily, mendix has a hook for tis, see - https://apidocs.mendix.com/7/client/mx.html#.addOnLoad
Hope this helps,