Using Custom Content Script to Change the Properties of a Field based on Displayed Value (before Sage CRM v7.2)

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Using Custom Content Script to Change the Properties of a Field based on Displayed Value (before Sage CRM v7.2)

  • Comments 4
  • Likes

Note: This type of customization has become easier in Sage CRM v7.2 using the new Client Side API).

The fields in screens are output with clear 'IDs' that allow the control of the field caption and data to be very easy. 

The HTML that makes up the display of a field like the comp_name is clearly divided into different <span> tags each with a clear ID.  Each field has a caption and its corresponding data.  Each is labelled in the HTML.

e.g.

  • _captcomp_name
  • _datacomp_name

This makes it very easy to be able to address the field in code.

For example the following code added to the custom content of the companyboxlong will change the colour of the data displayed in the Company Status field depending on its value.


<SCRIPT>
window.attachEvent("onload",setStatusColor);
function setStatusColor()
{
 switch (_Datacomp_status.innerHTML) {
    case "Active&nbsp;" :
        _Datacomp_status.style.color= "Green";
        break;
    case "Archive&nbsp;" :
        _Datacomp_status.style.color= "Gray";
        break;
    case "Closed&nbsp;" :
        _Datacomp_status.style.color= "Red";
        break;
    case "Inactive&nbsp;" :
        _Datacomp_status.style.color= "Yellow";
        break;
    default :
       _Datacomp_status.style.color = "Black";
 }
}
</SCRIPT>
 

 

Comments
  • Hi Jeff,

    that's short and easy to make, but big and useful for the customer.

    Christian

  • Hi Jeff - good advice!  I tried using similar coding to change the BACKGROUND color for the CASE status field ( _Datacase_status.style.background-color = "Yellow"; ), but it is ignored.  Same problem with font-weight ( _Datacase_status.style.font-weight= "bold"; ).  Any idea why?

  • Hello Spencer,

    try using

    _Datacase_status.style.fontWeight= "bold";

    thanks

  • Note: This type of customization has become easier in Sage CRM v7.2 using the new Client Side API).