This is the second 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
For a description for preparation of a Project Detail Page for JavaScript, see General Preparation.
This time, we will show or hide a field depending on the value of an Enterprise Custom field (ECF) available on this page. In article Project Detail Pages - Enhancements (Part 1) - Show/Hide a field based on the value of an internal field on the same page we used an internal field to evaluate the value. Now we will need evaluate the value of an ECF. On one hand, this is easier since we already know the GUID of this field. So there is no need to deal with different languages the get the GUID. The GUID of a field can easily be identified by editing this field from PWA Settings - Enterprise Custom Fields and Lookup Table.
On the other hand, it makes a difference how to get the value depending on read or write mode for the project. Moreover, we need to catch any changes on the value of the evaluated ECF in write mode, to apply the logic immediately.
In this sample, Enterprise Custom Field CostCenter will be hidden, if there are no Proposal Costs. GUID of Proposal Cost is “90c7672c-a519-e911-afbd-00155d80531a”. The variables FieldToCheckGUID and FieldToHide have to be adjusted accordingly.
<!-- Change path for jquery-2.1.1.min.js –> // Change GUID to Enterprise Custom Field to be checked: PWA Settings - Enterprise Custom Fields and LookUp Tables. Click on field name and get guid from the end of URL // Change To Enterprise Custom Field name to be hidden //A global variable is necessary
//MainFunction // Checked out //This function will return the value of Enterprise Custom Field if it is available on the page of a checked-in project //This funktion will evaluate the field value to define visibility requirement //Show/Hide a field |
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.