In a professional environment where document management and production are crucial, having powerful and flexible tools is essential. Imagine being able to design dynamic document templates directly from your Desktop client, integrating formulas and data from your database, and then generating these documents with a single click through an intuitive web interface. That’s precisely what 4D Write Pro and 4D Qodly Pro allow you to do!
In this week’s blog, we’ll explore how these two solutions complement each other perfectly to automate and optimize your document processes. You’ll discover how to create custom templates in 4D Write Pro and how, thanks to 4D Qodly Pro, web users can enter the necessary data, trigger document generation, and even choose to store them in the database or return them via a calculated attribute.
To demonstrate this process, we’ll use the Performance Review application, which is available for download. Get ready to transform how you create and manage your documents while simplifying your workflows and boosting efficiency.
Performance Review Application
Creating Templates in the Desktop Client
4D Write Pro is a powerful text processing tool whose main strength lies in its ability to create document templates linked to your database. This functionality allows you to automatically generate various types of documents: letters, contracts, invoices, catalogs, expense reports, and much more.
In Performance Review application, several document templates are used depending on the department involved. For example:
PO’s template
QA’s template
These templates incorporate dynamic formulas directly tied to the database, making it easy to create personalized documents for each department.
A form in the Desktop application allows you to create these templates in a simplified manner. To easily add formulas, a dropdown list suggests all the formulas relevant to the template.
These formulas are defined in a JSON file called “WPexpression.json”.
Here is an extract:
{ "expression": [{ "name": "Lastname", "formula": "This.data.review.Employee.Lastname" }, { "name": "Firstname", "formula": "This.data.review.Employee.Firstname" }, { "name": "CollaboratorName", "formula": "This.data.review.Employee.Firstname+\" \"+This.data.review.Employee.Lastname" } ] }
To learn more about the 4D Write Pro and ORDA, read this blog: ORDA and 4D Write Pro: The power couple!
To simplify table creation, the Table Wizard built into the 4D Write Pro Interface component is ideal.
For it to work seamlessly with our database structure, we added configuration files containing the formulas needed for Performance Review documents. For example:
{ "tableDataSource": "This.data.review.Skills.orderBy(\"Group asc\")", "columns": [{ "check": true, "header": "SkillName", "source": "This.item.Name" }, { "check": false, "header": "CheckCodeI", "source": "Choose(This.item.ID_Score=1; \"X\"; \"\")" }, { "check": false, "header": "CheckCodeP", "source": "Choose(This.item.ID_Score=2; \"X\"; \"\")" },{ "check": false, "header": "CheckCodeR", "source": "Choose(This.item.ID_Score=3; \"X\"; \"\")" },{ "check": false, "header": "CheckCodeE", "source": "Choose(This.item.ID_Score=4; \"X\"; \"\")" },{ "check": true, "header": "ScoreName", "source": "This.item.Score.Name" },{ "check": true, "header": "ScoreCode", "source": "This.item.Score.Code" } ], "breaks": [{ "label": "SkillGroup", "source": "This.item.Group" } ], "breakFormulas": [{ "label": "GroupName", "source": "This.item.Group" } ], "extraFormulas": [{ "label": "ScoreSkillName", "source": "This.data.review.ScoreSkill.Name" },{ "label": "ScoreSkillCode", "source": "This.data.review.ScoreSkill.Code" },{ "label": "CheckSkillScoreCodeI", "source": "Choose(This.data.review.ID_ScoreSkill=1; \"X\"; \"\")" }, { "label": "CheckSkillScoreCodeP", "source": "Choose(This.data.review.ID_ScoreSkill=2; \"X\"; \"\")" }, { "label": "CheckSkillScoreCodeR", "source": "Choose(This.data.review.ID_ScoreSkill=3; \"X\"; \"\")" }, { "label": "CheckSkillScoreCodeE", "source": "Choose(This.data.review.ID_ScoreSkill=4; \"X\"; \"\")" } ] }
With these formulas, creating a skills and scores table becomes very straightforward. After customizing the table, here’s the result:
To learn more about the configuration and capabilities offered by the Table Wizard, see:
- Blog: A Wizard to Create Tables with Data
- Training: 4D Write Pro and 4D View Pro meet 4D – the Next Level of Smart Templating
Filling in Data in the Web Client
Once the template is created, users enter the required data through an intuitive web interface. Thanks to 4D Qodly Pro, this step integrates seamlessly with your database, ensuring that the information entered corresponds to the fields defined in your templates.
For more details on setting up these interfaces, feel free to check out our previous blogs on:
- Create an Interactive List of Data with 4D Qodly Pro
- Building Dynamic Data Management in Qodly application: Create, Add, Edit, and Delete
Generating the Final Document
The final document is generated directly from the web interface. When a user clicks the dedicated button, the “On Click” event triggers the “selectedReview.generatePDF()” function.
Below is the code that manages the generation of the PDF document:
Function generateDocument()->$doc : Object
var $context : Object
var $template : cs.TemplateEntity
// Create context
$context:=This.createContext()
// Load template
$template:=This.Employee.Departement.Template.Template
// Create 4D Write Pro document
$doc:=WP New($template)
WP SET DATA CONTEXT($doc; $context)
WP COMPUTE FORMULAS($doc)
return $doc
exposed Function generatePDF()
var $WPdoc : Object
var $blob : 4D.Blob
// Generate WP document
$WPdoc:=This.generateDocument()
// Convert to PDF
WP EXPORT VARIABLE($WPdoc; $blob; wk pdf)
// Save in database
This.DocumentPDF:=$blob
This.save()
Permission
In the web application, users cannot access the Template table. However, the “Review.generatePDF” function needs to access this data to generate the PDF document. We set up a “promotion” on the function to achieve this.
- Creating the “generatePDF” privilege : In the Role and Privilege page, we define a new privilege named generatePDF.
- Granting read rights : We grant read permission to the Department and Template data classes. These rights are essential for locating the Write Pro template needed to generate the document.
- Promoting the “Review.generatePDF” function : We assign the Promote option to the Review.generatePDF function. With this promotion, when the function is called on the server, it automatically acquires the generatePDF privilege and can access typically restricted data.
This mechanism ensures that only authorized processes can temporarily extend their rights to perform specific tasks while maintaining high security and control over data access.
Voilà!
Next step
By combining 4D Write Pro and 4D Qodly Pro, you can automate the generation of dynamic documents by merging predefined templates and real-time data. This approach offers many benefits:
- Document Automation: Reduce manual tasks through dynamic templates.
- Workflow Optimization: Clearly separate template creation (Desktop client) from data entry (Web client).
- Time Savings and Higher Quality: A practical solution that improves productivity and the quality of generated documents.
We encourage you to try this approach in your projects and discover the benefits of integrating 4D Write Pro with 4D Qodly Pro. Feel free to comment to share your feedback or check out our other resources to further expand your knowledge.