Client-Side API: Hiding all null fields in a Screen

A customer had the need to empty hide fields on a screen.
This type of customization can be accomplished in more than one way within Sage CRM.  I have chosen to hide the fields using the client side API since this will satisfy the conditions of providing a single point of definition and control for the desired behaviour.
Below is a screen shot of the Company Summary page for a default instance of Sage CRM.  The page is made up of screens draw from multiple entities.  The CompanyBoxLong (company), AddressBoxShort (address) and PersonBoxShort (person).
There are 27 fields on the screen and each of these can be controlled using a client side script.  If you are not familiar with the client side API then you may wish to start by referring to the following article: https://www.sagecity.com/sage-global-solutions/sage-crm/b/sage-crm-hints-tips-and-tricks/posts/the-client-side-api
I added the following script into the Custom Content box of the company screen, CompanyBoxLong.
crm.ready(function()
{
var fieldlist = crm.fields();
var i;
for (i = 0; i < fieldlist.length; i++) {
if (!fieldlist[i].value()&&fieldlist[0].mode=='view')
{
fieldlist[i].collapse()
}
}
})
Notes:
  1. Remember to wrap the code with script tags.
  2. The code crm.ready(function()) defines the unit that will be executed once the page has finished loading.
    var fieldlist = crm.fields();  This line creates an array that contains all of the fields that it can find on the page.
    The script then uses a for...in loop to step through each of the fields.  There are 27 in my default instance.  If it finds a field that has is empty (has a null value) and the field is in 'view' mode it will collapse the field.  It is important to check that the field is in 'view' mode as I do not want to hide fields when the screen is in edit mode.
    I used collapse() rather than hide() as I did not want to leave 'spaces' in the screen where the fields had been.
This creates the effect below.
The API reference can be found on the Help Center: https://help.sagecrm.com/js-api/
You can find a short video about the Client Side API on the Sage Support and Training YouTube Channel.
Video:
Anonymous