I had weird issue when Dynamics 365 Project Operations out-of-the-box initializePage JavaScript function started to give error. I tried to debug it, but the error did not make any sense – null reference error in out-of-the-box initializePage onLoad event handler which were there by default coming from Project Operations layer.
The error message was appearing in the project main form. I had added addTabStateChange event handler in my JavaScipt code, so in the start I did not read the solution or file name – I was just assuming my code broke the execution. I was wondering, that clicking OK did not mean anything since my event handler was working fine. When I had this error many times and other developers in the project were mentioning it, I started to study it further.
I removed all my codes and the problem remain. Then I was sure, that the problem is in the files Microsoft provided.
I created Microsoft Support ticket and had 1,5 hour meeting with Project Operations engineer to figuring this error out. We had played around with customizations but we could not remove customizations with layers. This was because our custom form was missing the original layers since we had another problem with localizations and maybe because of that someone had remove the original layers.
TypeError: Cannot read properties of null (reading 'addTabStateChange') at t.initializePage (https://environment-dev.crm4.dynamics.com/%7b000000016278842%7d/webresources/msdyn_/Project/Project.Library.js:1:144731) at b._executeFunctionInternal (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.285816ec756fce3167debd6592c628d8.js:14:1212871) at b.execute (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.285816ec756fce3167debd6592c628d8.js:14:1211305) at https://content.powerapps.com/resource/uci-infra-bus/scripts/app.285816ec756fce3167debd6592c628d8.js:4:148863 at i (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.285816ec756fce3167debd6592c628d8.js:14:99372) at re._executeIndividualEvent (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.285816ec756fce3167debd6592c628d8.js:4:148837) at re._executeEventHandler (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.285816ec756fce3167debd6592c628d8.js:4:145655) at Object.execute (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.285816ec756fce3167debd6592c628d8.js:4:142708) at w._executeSyncAction (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.285816ec756fce3167debd6592c628d8.js:14:561277) at w._executeSync (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.285816ec756fce3167debd6592c628d8.js:14:561004) Error Details: Event Name: onload Function Name: msdyn.pssales.project.projectInitialization.initializePage Web Resource Name: msdyn_/Project/Project.Library.js Solution Name: ProjectService Publisher Name: microsoftdynamics
I remember that I had been fixing some naming errors that there were tab_new21 and some other out-of-the-box naming. I could not believe that those could cause the error. Support took time, so I continue investigating my self. The original Main form was working properly and we had source control and CI/CD pipelines, so I started to look sources a week a ago when there was no problem.

The only difference actually in the tabs was these naming changes, since I had removed code libraries and onLoad functions that I developed. I restored the names and then the error disappeared. I did not study the original JavaScript file anymore but I’m quite confident that this GUID in the name attribute or the default section should not be changed – OR ELSE you get the error that stops app business rules to work, does not get you data in new form and other quite vital functionalities stops working when the initializePage function could not run properly.
If it is not broken, don’t fix it
Old wisdom in IT business is, if something works and does not break anything – don’t modify it. Refactoring is good thing to make thins more beautiful and logical but sometimes those things just causes days or work and eventually you end up restoring the original solution – just because it works.