Category

Additional Formulas

Formatting Currencies

By Additional Formulas, Documentation, S-Docs Cookbook No Comments

Introduction

This article will teach you how to override the default currency format in your template and choose your own.

Let's say you would like to display “$235,000.00” as the Opportunity amount in your document rather than “235000,” which is the default formatting for the currency field. You can do this in one of two ways. The first option is to use S-Docs formatting, and the second is to use a Salesforce formula field.

Format Currency With S-Docs Syntax

To format currency using S-Docs syntax, you can simply add the correct formatting directly within your merge fields (add a space after the merge field name, followed by the currency format you would like):

[code lang="html"]${{!Contract.Total_Amount__c #,###}}[/code]

You can add this formatting yourself, or use the Insert Field button within the template editor to do so; currency options will appear for currency fields.

If the number/currency field is located in a related list column, you would need to edit the template source. Click the Source button and then locate the number/currency field within your template. You then need to replace the syntax to match the following:

[code lang="html"]<column format-number="#,###">quantity</column>
<column format-number="#,###.##" prefix="$">unitprice</column>
<column format-number="#.###,##" postfix="€">euro_price__c</column>[/code]

The example above shows the three supported formatting options. For others, you can use a formula field described below.

Format Currency With Salesforce Formula Fields

By adding the following formula field to your object, you leverage built-in Salesforce functionality. You would need to substitute your field name into the formula below (in place of “Amount”), and then drop the formula field into your S-Docs template. You do not need to add any of these fields to any page layout. You can add the dollar sign ($) to either the start of the formula or within the template design document proceeding your field.

[code lang="html"]IF(
Amount >= 1000000,
TEXT(FLOOR(Amount / 1000000)) & ",",
"") &
IF(
Amount >= 1000,
RIGHT(TEXT(FLOOR(Amount / 1000)), 3) & ",",
"") &
RIGHT(TEXT(FLOOR(Amount)), 3) & "." &
IF(<
MOD(Amount , 1) * 100 < 10,
"0" & TEXT(ROUND(MOD(Amount , 1), 2) * 100),
TEXT(MIN(ROUND(MOD(Amount , 1), 2) * 100, 99))
)[/code]

Note: This solution formats only the given value; it does not consider currency exchange rates. In such cases, you could use a combination of formulas: one to convert the currency based on the exchange rate, and another to format it correctly for your document.


Formatting Dates

By Additional Formulas, Documentation, S-Docs Cookbook No Comments

If you want to create a dated letter with the text “September 1, 2020” rather than the Salesforce formatted date-time, you can do so using S-Docs formatting syntax or using a Salesforce formula field. We recommend the first option where possible because it doesn’t require any Salesforce configuration changes.

Formatting Dates With S-Docs Syntax

Formatting dates with S-Docs syntax is easy; any Salesforce date and datetime field can be configured into any valid java pattern. Simply add a space in your date or datetime merge field, followed by the format you want:

[code lang="html"]{{!Quote.createdDate MM/dd/yyyy}}[/code]

You can also include time and timezone. For example:

[code lang="html"]{{!Quote.datetime__c MM/dd/yyyy hh:mm:ss TZ:America/New_York}}[/code]

Note: Make sure to use java time codes when using timezones.

If the date field is located in a related list column, use the following (you would need to edit the template source). Click the Source button and then locate the date column within your template.

[code lang="html"]<column format-date="MM/dd/yyyy">createddate</column>[/code]

The format-date syntax can accept a wide range of values. You can add minutes, timezones, etc. Pay attention to caps, as mm is minutes, whereas MM is month.

Use this reference to view all date formatting options:  https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Formatting Dates With Salesforce Formula Fields

If S-Docs syntax options do not meet your requirements, you can format dates by leveraging Salesforce formula fields. By adding the following formula field to your object, you can leverage Salesforce functionality. You would need to substitute your field name. You do not need to add these fields to any page layout. If you are working with a Date Field (not a DateTime field), see the next example for slight modifications needed.

[code lang="html"]CASE( MONTH( DATEVALUE(LastModifiedDate) ), 1, "January", 2, "February", 3, "March", 4, "April", 5, "May", 6, "June", 7, "July", 8,
"August", 9, "September", 10, "October", 11, "November", 12, "December", "-" )
+ ' ' + TEXT(DAY( DATEVALUE(LastModifiedDate))) + ', ' + TEXT(YEAR( DATEVALUE(LastModifiedDate)))[/code]



Top