How do I put calculated or derived info in a screen's top content?

1 minute read time.
 Here you can see it is possible to put calculated or derived information into the topcontent. This question actually came up the last time I was here in Germany, but I suppose it is a common requirement.

The example I am going to use is one that requires that the number of 'In Progress' cases and opportunities that are linked to the company should be displayed at the top of the screen. The other requirements are that only the total of the records that the user has a right to see should be displayed and that when the total is clicked it should open the list page for either the opportunities or the cases.
The way to put anything into a screens topcontent is to make use of 3 things. First a new "dummy" field that we no will not hold data and secondly the topcontent box and last the onCreate script of the dummy field when it is added to the topcontent box.
To add the dummy field, go to
Administration -> Customization -> Company
Within the fields tab, click 'new' and add a new field. I typically call mine just comp_dummy and have it as a text field with a length of 1 and set to be readOnly.
When the field is created. Click on the screens tab and then edit the companytopcontent screen.
Add the new dummy field into the screen.
Add the following code into the Createscript box:

[code language="javascript"]
var oppoRecord = CRM.FindRecord("opportunity","oppo_status='In Progress' and oppo_primarycompanyid="+CRM.GetContextInfo("company","comp_companyid"));
var caseRecord = CRM.FindRecord("cases","case_status='In Progress' and case_primarycompanyid="+CRM.GetContextInfo("company","comp_companyid"));
Caption = "
";
Caption +=CRM.GetTrans("Tabnames","Opportunities");
Caption +=":
";
Caption +=""+oppoRecord.RecordCount+"";
Caption +="
" ;
Caption +=CRM.GetTrans("Tabnames","Cases");
Caption +=":
";
Caption +=""+caseRecord.RecordCount+"";
Caption +="
" ;
[/code]
Parents Comment Children
No Data