Pages

Thursday, December 24, 2015

SP.Core.js file was not initialized during page post back in SharePoint 2013

Problem

Today we had an issue where the sp.core.js file was not initialized after the post back of a application page. So the other SharePoint JavaScript files like sp.js, sp.runtime.js threw errors (As in the screenshot below). So, the functionalities didn’t work as expected.

Capture

Environment

The sp.core.js file was referenced in the master page and our custom JavaScript file (the file where our functionalities are implemented. We were opening a modal pop up implementing some logics) was referenced in the aspx page. Our client wanted us to work only in the custom JavaScript file and not in the master page or in application page.

Solution 

We used registerSod function which is available in SharePoint Script On Demand (SP.SOD) framework in order to load build in SharePoint JavaScript libraries.
 
  1. /* SP.SOD.registerSod(key value (any unique string), path of the script file); --- */
  2. SP.SOD.registerSod('sp.core.js', '\\_layouts\\sp.core.js');
  3. /*  executeFunc is used to execute the file mentioned above. using dummy function --- */
  4. SP.SOD.executeFunc('sp.core.js', false, function () { });
  5. SP.SOD.registerSod('sp.js', '\\_layouts\\sp.js');
  6. SP.SOD.executeFunc('sp.js', false, function () { });
  7. SP.SOD.registerSod('sp.ui.dialog.js', '\\_layouts\\sp.ui.dialog.js');
  8. SP.SOD.executeFunc('sp.ui.dialog.js', false, function () { });

Reference

http://www.vlieshout.net/sharepoint-2013-lazy-loading-javascript/






Wednesday, December 23, 2015

Remote debug SharePoint Provider hosted add-in deployed in Azure

Steps

  1. Deploy your provider hosted add-in to azure website with the configuration setting as “Debug”. debug1
  2. On Visual Studio (My version is 2013) go to server explorer and sign into your azure subscription. imageimage
  3. Once you are success all your azure services will be listed. image
  4. Now right click on your azure website where the provider hosted app is deployed and click in the Attach debugger.  image 
  5. Now you can debug your provider hosted app
image