This is the fourth part of articles discussing Project Detail Page enhancements:
- Show/hide a field depending on the value of an internal field on the same page
- Show/hide a field depending on the value of an Enterprise Custom field on the same page
- Show/Hide a field based on the value of an internal field using REST
- Show/Hide a field based on the value of an Enterprise Custom Field without Lookup Table using REST
This time, we will show or hide a field depending on the value of an internal field not available on this page. To get the value, we will use REST API. There are two restrictions:
- This code will not work with Project Server 2013 (and below). Project Server 2013 does not provide internal field information using REST. You can make it work with OData, but I avoid this since it requires more permissions for Team Members than usually provided.
- This code will not work in delegate session in on premise environments. Within a delegate session, REST is not available per 2019-01-28 in Project Server 2013, 2016 and 2019. To test, open a delegate session and enter “http(s)://<SERVER>/PWA/_api/ProjectServer/Projects” as address in browser. You will get the following result:
In this sample, Enterprise Custom Field CostCenter will be hidden, if an Enterprise Custom field with GUID “90c7672c-a519-e911-afbd-00155d80531a” = 0 or is empty. To use different fields change FieldToCheck and FieldToHide accordingly. Using the appropriate line for “var RESTAppendix”, you can decide if you want to retrieve the value of the saved or the published version of the project.
Copy above code into a text editor, modify at least the marked sections, save with file extension "js" or "html", and upload to your script library.