4D Write Pro documents often contain formulas returning data or calculations depending on the database. Thanks to the use of contexts, associating that data with documents is now child’s play!
In this blog post, we’ll see how the combination of 4D Write Pro documents with data retrieved using ORDA makes the code clear and easy to maintain.
ORDA and 4D Write Pro In Action
4D Write Pro and data
Whether you’re dealing with letters, e-mail campaigns, catalog generation, invoice printing, etc., the data displayed or printed always comes from the database. Thanks to ORDA, access to that data is more and more efficient, and the new concept of contexts will allow you to efficiently exploit the information in your documents.
A context? What is A context?
A context is an object: An entity, an entity selection, or any object composed of as many attributes as necessary. Once created and associated with a document, this context can be used directly within the document using the This function, which you are now familiar with.
A simple case: Mailing CAMPAIGN
Let’s say you have a People dataclass and you want to send e-mails to a selection of these people. The first thing to do is to create the letter template with the information to be communicated, and then insert data from each person (their name, address, etc.) in that template. This process is well known, but we’ell see how to insert this information once the context is created.
For each person…
Before printing your template letter, associate each entity of your selection with the template.
And that’s it!
For each ($person; $es_people)
WP SET DATA CONTEXT($template; $person)
End for each
But what does the model contain?
The $person context is accessible in the model via the This.data formula.
If the $person entity has a lastname attribute, this attribute will be accessible via This.data.lastname.
Your template letter will therefore contain these kinds of expressions:
A function in the PeopleSelection class
For the beauty of the code, you can create a function that will receive the template printed with the entities’ data.
Class extends EntitySelection
Function mailing($template : Object)
For each ($people; This)
WP SET DATA CONTEXT($template; $people)
End for each
The call of this function will be done as follows in an exquisite way:
// create entity selection
// mailing based on 4D Write Pro template
More information can be found in the documentation. And feel free to share with us your feedback and experience on the 4D forum.