Rob I really like what you’ve done (I didn’t know you wrote Javascript ) I would just suggest using a function to handle the label text like so… instead of this
// Replace custom fields API name with their labels. You need to hard code label names.
if (value1 === "Service_Location__c")
{<br> value1 = "Service Location";<br>}
I would do this: (I realized after the fact that you’ll never get an __r field…)
//you can use a hack-ish function to format all instances correctly<br>
//and avoid hardcoding labels...<br>
function fixFieldFormat(field){<br>
if(field.indexOf("__c") != -1){<br>
if(field.indexOf("__r.") != -1){<br>
var start = field.indexOf("__r.") + 4;<br>
var end = field.length - start;<br>
console.log(end);<br>
field = field.substr(start,end);<br>
}<br>
var trim__c = field.replace("__c","");<br>
var trim_ = trim__c.replace(/_/g," ");<br>
}<br>
return trim_;<br>
}<br>
//then just call it<br>value1 = fixFieldFormat(value1);