Access field value from database and display the same on the screen using client side script

By | April 6, 2012

Consider a scenario where we need to populate a field value from another table to Company Summary screen. To achieve the same we need to access the database to get the field value and then display the same on the screen.
For example FinalTotal is a field in any other table in CRM. You want this value to be populated in field on Company summary screen i.e. comp_finaltotal. The easiest way to do this will be as follows.
Edit the company summary screen from customization section. On the Create script section of field comp_lastyeartotal put the below script.
var FinalTotal = 0;
var qryfinaltotal = “select finaltotal from < your table name > where < whereclause >”;
var recfinaltotal = eWare.CreateQueryObj(qryfinaltotal);
            FinalTotal = recfinaltotal (“finaltotal”);
Caption = “Last Year:” + “< input type=hidden id=hdnlstyr  name=hdnlstyr  value=’”+ FinalTotal +”’ >”
This script will push the value to the hidden variable hdnlstyr.
Then on the Custom content area you can access this value from client side script as given below.
var FinalTotal = document.EntryForm.hdnlstyr.value;
You can use this value to whatever field you want from client side java script.