Skip to main content

Project Site - Project/Custom fields displayed on Project Site or Project Workspace

If you want to display project fields or project custom fields on your project site, like in the image below, there are only a limited number of possibilities. One of them is of cause to use an App, but that limits the layout to the App.


In this post, I will walk you through how to insert a script that loads and displays any project field you like. The Script is really easy to configure.
I should mention that I found part of this solution at Poul's Project blog (link) but his solution was very difficult to configure so I rewrote the whole code.

First thing you need is to upload your JQuery script file to the PWA site. if you already have a JQuery file uploaded it will properly do fine.

Download the JQuery file here http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js and save it on your desktop.

Go to the Site Settings of the PWA and click on Master Pages.

Upload the JQuery file here and publish it.
View properties of the file and copy the JQuery file link.
Now go to your Project Site or Project Site template (if you want it on all sites) and insert a Content Editor Webpart.
Edit source of the webpart.
Paste the following script into the webpart.

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  
 <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.0/css/jquery.dataTables.css">  
 <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.0/js/jquery.dataTables.js"></script>  
 <script type="text/javascript" src="/_layouts/15/sp.debug.js"></script>  
 <script type="text/javascript" src="/_layouts/15/sp.js"></script>  
 <div id="pData"></div>  
 <script type="text/javascript">  
   var ProjectFields =  
         [  
           //Project fields  
           // Header      Name  
           ['Project Name', 'ProjectName'],  
           ['Description', 'ProjectDescription'],  
           ['Project Owner', 'ProjectOwnerName'],  
           ['% Complete', 'ProjectPercentCompleted'],  
           ['Project Work', 'ProjectWork'],  
           //['Project Cost', 'ProjectCost'],  
           ['Project Health', 'ProjectHealth']  
         ];  
   var ProjectUID;  
  ExecuteOrDelayUntilScriptLoaded(getProjectUIDProperty, "sp.js");  
  function getProjectUIDProperty()  
  {  
    $('#pData').empty();  
    $('#pData').css('display', 'table');  
    $('#pData').css('width', '100%');  
    var row = $('<div />');  
    row.css('display', 'table-row');  
    var row_below = $('<div />');  
    row_below.css('display', 'table-row');  
    ProjectFields.forEach(function (field, i)  
    {  
      var cellContent = $('<div />');  
      cellContent.css('margin', '2px');  
      cellContent.css('border-bottom', '0px solid');  
      //cellContent.css('max-width', '400px');  
      cellContent.css('font-weight', 'bold');  
      cellContent.text(field[0]);  
      var cell = $('<div />');  
      cell.css('text-align', 'center');  
      cell.css('display', 'table-cell');  
      cell.css('vertical-align', 'middle');  
      cell.append(cellContent)  
      row.append(cell);  
      var cellContent_below = $('<div />');  
      cellContent_below.css('margin', '2px');  
      cellContent_below.css('border-bottom', '1px solid');  
      //cellContent.css('max-width', '400px');  
      cellContent_below.css('font-weight', 'bold');  
      var cell_below = $('<div />');  
      cell_below.css('text-align', 'center');  
      cell_below.css('display', 'table-cell');  
      cell_below.css('vertical-align', 'middle');  
      cell_below.append(cellContent_below)  
      row_below.append(cell_below);  
    });  
    $('#pData').append(row);  
    $('#pData').append(row_below);  
         var ctx = new SP.ClientContext.get_current();  
         this.web = ctx.get_web();  
         this.props = this.web.get_allProperties();  
         ctx.load(this.web);  
         ctx.load(this.props);  
         ctx.executeQueryAsync(Function.createDelegate(this, gotProperty), Function.createDelegate(this, failedGettingProperty));  
       }  
 function gotProperty() {  
          ProjectUID = this.props.get_item('MSPWAPROJUID');  
                      LoadProjectData();  
       }  
 function failedGettingProperty() {  
         alert('Error: ' + args.get_message());  
       }  
 function LoadProjectData()  
 {  
   var selectStr = '';  
   ProjectFields.forEach(function (field, i)  
   {  
     if (i == 0)  
     {  
       selectStr = field[1];  
     } else  
     {  
       selectStr = selectStr + ',' + field[1];  
     }  
   });  
   var data = $.ajax({  
     url: _spPageContextInfo.siteAbsoluteUrl + "/_api/ProjectData/Projects(guid'957d5fcd-5cbf-e111-9f1e-00155d022681')?"  
            + "$select=" + selectStr,  
     type: "GET",  
     dataType: "json",  
     headers: { Accept: "application/json;odata=verbose" }  
   });  
   data.done(function (data, textStatus, jqXHR)  
   {  
     try  
     {  
       var row = $('<div />');  
       row.css('display', 'table-row');  
       var row_below = $('<div />');  
       row_below.css('display', 'table-row');  
       ProjectFields.forEach(function (field, i)  
       {  
         var value = data.d[field[1]];  
         try{  
           var numValue = parseFloat(value).toFixed(2);  
           if (numValue != 'NaN')  
           {  
             value = numValue;  
           }  
         } catch (ex)  
         { }  
         var cellContent = $('<div />');  
         cellContent.css('margin', '2px');  
         cellContent.css('border', '0px solid');  
         //cellContent.css('max-width', '400px');  
         cellContent.css('height', '100%');  
         cellContent.text(value);  
         if (value == 'Red')  
         {  
           cellContent.css('background-color', 'red').css('color', 'white');  
         }  
         if (value == 'Yellow')  
         {  
           cellContent.css('background-color', 'orange').css('color', 'white');  
         }  
         if (value == 'Green')  
         {  
           cellContent.css('background-color', 'green').css('color', 'white');  
         }  
         var cell = $('<div />');  
         cell.css('text-align', 'center');  
         cell.css('display', 'table-cell');  
         cell.css('vertical-align', 'middle');  
         cell.append(cellContent)  
         row.append(cell);  
         var cellContent_below = $('<div />');  
         cellContent_below.css('margin', '2px');  
         cellContent_below.css('border-top', '1px solid');  
         //cellContent_below.css('max-width', '400px');  
         cellContent_below.css('height', '2px');  
         var cell_below = $('<div />');  
         cell_below.css('text-align', 'center');  
         cell_below.css('display', 'table-cell');  
         cell_below.append(cellContent_below)  
         row_below.append(cell_below);  
       });  
       $('#pData').append(row);  
       $('#pData').append(row_below);  
     } catch (ex)  
     {  
       alert(ex.get_message());  
     }  
   });  
   data.fail(function (jqXHR, textStatus, errorThrown)  
   {  
     alert("Error retrieving project data: " + jqXHR.responseText);  
   });  
 }  
 </script>  

Replace the JQuery script in the top of the file with the link to your local script.
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  

Replace the Project Fields with the fields and headers you want to display.
var ProjectFields =  
         [  
           //Project fields  
           // Header      Name  
           ['Project Name', 'ProjectName'],  
           ['Description', 'ProjectDescription'],  
           ['Project Owner', 'ProjectOwnerName'],  
           ['% Complete', 'ProjectPercentCompleted'],  
           ['Project Work', 'ProjectWork'],  
           //['Project Cost', 'ProjectCost'],  
           ['Project Health', 'ProjectHealth']  
         ];  

Click OK and save the webpart page.

The fields will now be displayed on your Project Site.


Note: The Content Editor webpart sometimes converts the Javascript into HTML, so after clicking Save you cannot edit the script anymore. Remember to keep an offline copy of the script while modifying it.

Comments

Popular posts from this blog

Sharepoint 2013 - Fullscreen mode/hide quick launch

If you want to hide the quick launch on a SharePoint page or web part page in 2013 you could of cause use CSS scripts as in 2010.
But as a new thing in 2013 the user have the possibility to click on full screen mode. so why not load your page in this mode and then the user can choose to exit the mode if he prefers.

Add a content editor webpart to your page and click on Edit HTML from the ribbon.
Add the following code:

<script type="text/javascript">
window.onload = function()
{
  SetFullScreenMode(true);
}
</script>

Install DLL in GAC - Windows 2008/2012 (Using Powershell, No GacUtil.exe)

If you want to install a DLL in the GAC and do not have the GACUtil.exe available. Powershell is properly the easiest way to procede.

Before Powershell you would properly just drag the DLL file into the C:\Windows\Assembly but this option is usually not available anymore.

Powershell - Add DLL to GAC So to install a DLL file in the GAC simply execute the below Powershell script. Remember you migth want to run the Powershell prompt as an administrator.
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")$publish=New-ObjectSystem.EnterpriseServices.Internal.Publish$publish.GacInstall("c:\temp\MyDllFile.dll")iisreset
The first line adds a reference to the assembly we need to be able to mange the GAC.
The second and third lines retrives the GAC object and publish a new DLL file to it.
The last line resets the Internet Information Services. This is only needed if your DLL file is used in a websi…

Reporting on Microsoft Planner or Microsoft Staffhub!

Reporting on Planner or StaffHub!


For a long time I have been waiting for the reporting API for Planner and Staffhub. Today I got tired of waiting and found another way to do it.

I manage to create a PowerBI report based on all the planner plans I have access to and the same method will work for Staffhub and properly many other services such as Microsoft Tasks, Microsoft Forms, etc. 


How?Easy, but requires some Azure, Flow and PowerBI knowledge. These are the steps to I used: 1.Create an Azure Blob to hold the data 2.Create a Flow to save Planner data in the Blob 3.Access the Blob from PowerBI Azure – Blob!So first, lets create a Blob. No, not that kind of Blob. Access the Azure portal - https://portal.azure.com/ Select New and search for “storage account” Fill out the form and click create. I kept all settings to their default Access the new storage and locate/copy the Storage Account Name and Access Key – you will need this for connections to Flow and PowerBI. Next let’s create a Blob Container an…