Thank you for the update, and good to hear that you have resolved this issue.
Certainly the replacement code is the form we recommend for initializing a Formativ Portal.
I suspect that the strange behavior is caused by more than one copy of exactly the same Portal. The first code block could permit multiple copies of a Portal, if the applet is executed more than once. This might happen inadvertently if the applet is configured (via GroupWise integrations) to be triggered by more than one event – not only startup. Just an idea.