ORDA and 4D Write Pro : The power couple!

Automatically translated from English

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)
 WP PRINT($template)
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)
  WP PRINT($template)
End for each 

The call of this function will be done as follows in an exquisite way:

// create entity selection
$es
:=ds.People.all()
// mailing based on 4D Write Pro template
$es
.
mailing($template) 

Conclusion

More information can be found in the documentation. And feel free to share with us your feedback and experience on the 4D forum.

Roland Lannuzel

• Product Owner & 4D Expert •

After studying electronics, Roland went into industrial IT as a developer and consultant, building solutions for customers with a variety of databases and technologies. In the late 80’s he fell in love with 4D and has used it in writing business applications that include accounting, billing and email systems.

Eventually joining the company in 1997, Roland’s valuable contributions include designing specifications, testing tools, demos as well as training and speaking to the 4D community at many conferences. He continues to actively shape the future of 4D by defining new features and database development tools.