Tuesday, February 11, 2014

Project Server - Are you sure you want to navigate away from this page

When creating or editing project in project Server, it implies that you change lots of field values in Project Detail Pages.

After every change on Project Detail Page, you need to click on Save button in Ribbon for changed to be saved. If you don't do that (and you try to navigate away from that page without saving), you will be prompted with the following message: "Are you sure you want to navigate away from this page?"



Prompt window for saving changes in Project Server


This is perfectly normal behavior of Project Server.

The problem starts when this message appears when you haven't made any changes on the Project Detail Page. For example: You have made changes on your Project Detail Page and then click on the Save button. But, when you try to navigate away from that page, you get this message. I was confused because I didn't know did Project Server really saved my changes or not.

This seems to be a bug in Project Server this happens when you have more than one multiline text box fields on the page.
I have found one one solution for this problem.

NOTE: This solution changes default scripts of Project Server. It is not recommended by Microsoft to customize this scripts. Actually, it is not allowed and all changes you make to this scripts can cause unexpected behaviour of Project Server.

Now, after you have been properly warned, this is the solution:

1. Go to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\INC\PWA\LIBRARY

2. Find script called "ProjectServerScripts.debug.js" and make a backup of that script (we are going to change the existing script so it is good to have a backup).

3.  Open script "ProjectServerScripts.debug.js" and in it find following code:

handleSaveCommand:function(command, properties, sequenceNumber){ULSBk9:;
    eval('PDPButton.SaveData(null);');
    return true;

},

4. Add one line (marked red) to that method and save changes:

handleSaveCommand:function(command, properties, sequenceNumber){ULSBk9:;
    eval('PDPButton.SaveData(null);');

    window.onbeforeunload = function(e){}
    return true;

},