I have a javascript in Footer text. F12 console reported: “Uncaught ReferenceError: HelpDesk is not defined”. I have found out that userfn.js has only one word - ‘undefined’ and code placed in [Client Scripts]-[Global][pages with headers/footer][Global Code] doesn’t work.
I didn’t managed to solve it, delete template cache and regenerate the file didn’t help.
I have a javascript in Footer text. F12 console reported: “Uncaught ReferenceError: HelpDesk is not defined”.
There is no “HelpDesk” in PHPMaker, if it is your own script, make sure you have include it before using it.
Note that JavaScript is loaded asynchronously, if you use JavaScript in footer, you better move it to client side global Startup Script, see the topic Server Events and Client Scripts in the help file.
The problem is that phpmaker doesn’t generate code into file userfn.js which I put into [Client Scripts]-[Global][pages with headers/footer][Global Code]. “HelpDesk” script (javascript link) is just one of a scripts I use there.
If I manually add my code directly into userfn.js file (from [Client Scripts]-[Global][pages with headers/footer][Global Code]) then all works as it should.
The question is how to generate userfn.js with code inside.
I just removed one old script from [Client Scripts]-[Global][pages with headers/footer][Global Code] and regenerate the file, now I can see my “HelpDesk”. If I put that code back then userfn.js is “undefined”.
One of the causes why the generated userfn.js will produce “undefined” word in it is, the Javascript code that put from the following location is not valid.
For example, I put this Javascript code in “Client Scripts” → “Global” → “Pages with header/footer” → “Global Code”:
window.mySuccessCallback = function () {
Swal.fire(“Successfully done!”), “”, “success”);
};
As you can see, that code above is not valid, because I accidentally added “)” after the first param in “fire” method of SweeAlert2. Since it is not a valid Javascript code, then PHPMaker will generate “undefined” inside the userfn.js file.
If I fix the code become:
window.mySuccessCallback = function () {
Swal.fire(“Successfully done!”, “”, “success”);
};
The problem was in my script which was automatically converted by phpmaker v2020 from v12 (ew_ → ew.). I have some functions to valid names which can be found in phpfn.php file.