4D Blog

Home Tips Creating Dynamic Documents with 4D Write Pro in Qodly application

Creating Dynamic Documents with 4D Write Pro in Qodly application

April 1, 2025

Tips

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

blank

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.

blank

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.


blank

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:

blank

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.

blank

 

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.

 

A dark-themed user interface section with two tabs: "Roles" and "Privileges," with "Privileges" currently selected in purple. Below, a "Privileges" section lists three privilege items:

    "guest" with an info icon.
    "createReview" with edit and delete icons.
    "generatePDF" with edit and delete icons, highlighted with a purple border.

A plus (+) button in the top right allows adding new privileges.

  • 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.

 

A dark-themed user interface panel titled "Include a privilege." At the top, several privilege tags such as "createReview," "none," "authentify," "user," and "hr" are displayed. Below, there is a search bar labeled "Search available permissions" and a button to create a permission. Two buttons, "Reset" (red) and "Clear" (purple), are present.

A table lists different permissions with columns for Read, Create, Update, Delete, Execute, and Promote.

    "Department" has no checkboxes selected.
    "Review.generatePDF" has Read and Promote checked.
    "Template" has only Read checked.

On the right, a toggle switch labeled "Show inherited permissions" is set to off.

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à!

blank

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.

Discuss

Tags 20 R8, 21, 4D Qodly Pro, 4D Write Pro, PDF, Performance Review Application, Qodly Studio, Tutorial, Word processor

Latest related posts

  • September 15, 2025

    Find the right spot in your 4D Write Pro document with AI

  • September 2, 2025

    Intelligent 4D Write Pro document analysis with AI

  • August 25, 2025

    ORDA – Constructor and touched event – Detailed behaviour through a network

Vanessa Talbot
Vanessa Talbot
• Product Owner •Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy