Display field history for the Case object.

I spent some time with this over the weekend (cuz history has been needling me for a long time) and developed a javascript solution that more completely matches the standard salesforce implementation of field level history.

Here is the end result (compared side by side with the template solution I showed above).

You can see the following:

  1. Appropriate distrinction between case created and description changed
  2. Custom fields have the API names replaced with labels.
  3. The ID values associated with Owner change have been removed.

Here is how.

  1. Add the “Field” field from your case history model to your table. Change the Field Renderer property to “Custom (run a Snippett)” and give it some name like “CaseHistory”

  1. Go to the Resources Tab and add a new Javascript resource.
  • The Type should be "In-Line (Snippet)
  • Give it the same name as you used in the field properties above.

The code in the snippet should look somthing like this. You will need to adjust to your particular situations.

var params = arguments[0], 
$ = skuid.$; 
var field = arguments[0]; 
var value1 = arguments[1]; 
var model = field.model; 
var row = field.row; 
var value2 = row.OldValue; 
var value3 = row.NewValue; 
var text; 
// Replace custom fields API name with their labels. You need to hard code label names. 
if (value1 === "Service_Location__c"){ value1 = "Service Location"; } 
// Handle case creation if (value1 == "created") 
{ text = 'Case Created'; } 
// Handle text fields where change values are not documented. 
else if (value2 === null && value3 === null) { text = 'Changed ' + value1; } 
// Handle "first entry" situations where "changed from" value is not present. 
else if (value2 === null && value3 !== null) 
{ text = 'Changed ' + value1 +' to <b>"' + value3 + '"</b>'; } 
// Handle full change record where Field, Changed From and Changed To fields are present. 
else if (value2 !== null) 
{ text = 'Changed ' + value1 + ' from "'+ value2 + '" to <b>"' + value3 + '"</b>'; 
// If changed from value looks like an ID, hide the row - since the name field is already there. 
var n = value2.indexOf("00"); 
if (n===0) 
$(document.body).one('pageload',function() { field.element.closest('tr').remove(); }); } } 
// Populate text into table cell 
field.element.append(model.mergeRow(row,text));