Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

script called as many times as masterpage is used


Former Community Member

When people build a form with n pages, and a global script within, there's a strange behaviour with the script.

When this form loads, this global script is called as many times as the total number of pages in my form, like if it was instanciating it again and again

How avoid it ?

Thanks for your help !
1 Reply


Level 5
Here some sample JavaScript code that might help you resolve the issue.

var curPageNum = xfa.host.currentPage + 1; // this is index

// based starts with 0

if (curPageNum == 1) {

// run your current script here then it will run only one

//time on page 1