There’s a setting on the exportData function “useAPINamesForHeaders” which you can set to false, that helps a lot and may be all you need in some instances.
The following also allows you to change the value for certain fields:
/* include out all your fields one by one, it may be possible to instead pull in all model fields via model.getFields() */
var fieldsToUse = [
'Id',
'Account__r.Name',
'First_Name__c',
'Date_of_Birth__c'
]
/* bring in your model */
var model = skuid.$M(‘yourModelName’);
/* map all the fields you listed in the above array to actual field objects from your model. you could probably skip the above set fieldsToUse with model.getFields() or something */
var fieldsWithCorrectLabels = $.map(fieldsToUse, function (v) {
var actualField = model.getField(v);
/* helpful to make sure you know what field ids you’re getting */
console.log(actualField.id);
console.log(actualField.label);
/* for any field that you want to change, use an if statement based on the field id*/
if (actualField.id === ‘Account__r.Name’){
return {
id: actualField.id,
name: actualField.name,
label: 'Company Name'
};
}
/* for all other fields, use the Salesforce label as your column header */
else {
return {
id: actualField.id,
name: actualField.name,
label: actualField.label
};
}
});
/* export data, your fields array is the result of the above */
model.exportData({
fields: fieldsWithCorrectLabels,
doNotAppendRowIdColumn: true,
useAPINamesForHeaders: false
});