To display a date field in a localized format during a document merge, such as in Spanish ("25 enero 2024"), there are two recommended approaches:
1. Create a Formula Text Field in Salesforce
Use a custom formula field on the object to format the date with translated month names. Here's an example formula for Spanish:
salesforce
CopyEdit
CASE(
MONTH(Date_Fieldc),
1, "enero", 2, "febrero", 3, "marzo", 4, "abril",
5, "mayo", 6, "junio", 7, "julio", 8, "agosto",
9, "septiembre", 10, "octubre", 11, "noviembre", 12, "diciembre", ""
) & " " & TEXT(DAY(Date_Field__c)) & " " & TEXT(YEAR(Date_Fieldc))
You can then include this field in your data source and use it in your merge template with {{FormattedDate__c}}.
2. Use a Calculated Field in Apsona Report
If using an Apsona single-step or multi-step report as the data source for your merge, create a calculated field with JavaScript to dynamically format the date:
javascript
CopyEdit
["enero", "febrero", "marzo", "abril", "mayo", "junio",
"julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"]
[new Date({!Date_Field}).getMonth()] + " " +
new Date({!Date_Field}).getDate() + " " +
new Date({!Date_Field}).getFullYear()
This approach allows full control over formatting and makes the output previewable directly in the Apsona report before merging.