This is the third 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
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 internal field Cost = 0. 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.