In addition to dashboards and charts, Creatio also has options for creating and printing out documents or reports. This feature is great when you need to make something available in a printed format.
The basic idea of a printable is to first define the data needed to drive the report, and then create a Microsoft Word template that acts as the host of the report and shows whatever data needs to be displayed.
Once the data points are placed in the rights spots on the printable, they show up using the default system formatting – as a number, date etc. However, we may want special formatting in some cases, and Creatio provides a nice way to define some code that will format data any way we choose.
In this example, we want to present a report that looks like a certificate to be sent out to someone. However, when the report is generated, the standard date format needs some adjustment. So, we will explore a few ways to format the date starting from a simple to a more complex format.
First, let’s set up a simple Word template for the report. It uses the Contact’s name and the Certification Date fields on the report template. Here is how the template looks:
When we execute this report for a given contact in Creatio, the output looks like this:
Now that we have the basic template set up, let’s work on the formatting of the date. We are going to set up four different formats:
- BasicDate
- DateWithMonthName
- DateWithMonthNameAndYear
- DateWithMonthNameYearAndTime
The first step is to set up some code that does the formatting. To do this, navigate to the advanced settings area and create a “Source Code” schema that will allow you to write the C# formatting code.
Then, use the code in the following script to set up the necessary formatting:
Then, save and publish the code. Now it should be ready to use. Notice how each formatting function has a code decorator at the top. For example:
[ExpressionConverterAttribute("BasicDate")]
This is what tells Creatio the “friendly” name of the function when the report is being designed. In this case, the function is going to be referenced as “BasicDate”. Similarly, each formatting function has its own unique name, which then gets referenced wherever it is used in the report template.
The next step is to create a printable named “Certification”.
Notice how the report data has the “Certification Date” and then the same field, but with a special syntax. These are basically the same date field, but with an altered name that contains the name of the formatting function. The syntax is:
OriginalCreatioFieldName[#FriendlyFormattingFunctionName#]
Let’s add all these formats to the report, which makes it easier to then switch between formats as needed.
Set up the printable report template to contain the necessary formatting function, and it should show you the correct format on execution. The sections below describe each format and how it looks when used to generate our printable Certificate.
BasicDate:
Format: "MM/dd/yyyy"
This format simply uses the month/date/year format in case we only want to show the date without the time at which the certification was achieved.
DateWithMonthName:
Format : "MMMM dd, yyyy"
In this case we are formatting the date to use a more descriptive date with the month name and a comma to give a space before the year value is printed.
In this formula the “MMMM” value shows the month name instead of the month value “MM” in the previous formula.
DateWithMonthNameAndYear:
Format: "dddd, dd MMMM yyyy"
This is like the previous format, but with the day name added at the beginning. It’s achieved by using the “dddd” code in the format specification. Note that if just “dd” is used, it provides the day number in the corresponding month.
DateWithMonthNameYearAndTime:
Format: "dddd, dd MMMM yyyy 'at' hh:mm tt"
In this format we use the day name, the day number, the month name and a four-digit year. And we also want to add the time at the very end to show the exact time at which the certification was achieved. Notice how the formula has the word ‘at’ added in it to make the date more verbose.
This is just an example of how date values can be formatted for your printable reports. Obviously, there are lots of combinations of formats involving the year, month, day, and time parameters that can be set up to produce all kinds of date and time formats. Hopefully the above examples give you a starting point to get the exact format you need.