4D Blog

Home Product 4D Write Pro and formulas

4D Write Pro and formulas

February 10, 2020

Product

With 4D v18 R2, 4D Write Pro is able to manage formula objects inside documents. To do so, four new commands have been created: WP Get formulas, WP Insert formula, WP Compute formulas, and WP Freeze formulas. They all can be used with intuitive targets like document, body, headers, etc. And as you may have guessed from the command names, formulas are no longer text expressions but powerful formula objects!

HDI: GetSetFormulas 

All at once

The first command, WP Get formulas, enables getting all of the formulas within a specific target. Of course the first target that comes to mind is the full document itself, but it could also be a more specific part of the document such as the body, the second section, the left header, just name it! This command returns a collection of objects containing the formula, the range (when the expression is inline), or the anchoredID when the expression is attached to an anchored picture.

Note: The formula object now has a readable attribute called source. This attribute is very useful for finding and replacing actions. (see below)

The WP Compute formulas and WP Freeze formulas commands can be used in a very similar way (i.e., using a target). You can re-evaluate all of the document’s expressions, or you could decide to freeze only the expressions belonging to the footers. Simple and logical.

// find all expressions of the document
C_COLLECTION($_expressions)
$_expressions:=WP Get formulas(WParea)

one by one

The fourth command, WP Insert formula, enables inserting an expression (as a formula object) within any given range. It can also be used to replace existing expressions (once found by the WP Get formulas command).

Here’s a simple replacement example: your document contains Current date expressions and you’d like to replace all of them with a formatted string such as “Thursday 14 November 2019“.

  // define what to find
$find:=Formula(Current date)
  // define the replacement
$formula:=Formula(String(Current date;System date long))
  // find all expressions of the document
$_expressions:=WP Get formulas(WParea)
  // query the collection (could have been done on previous line, but easier to read this way!)
$_expressions:=$_expressions.query("formula.source = :1";$find.source)
  // then replace each expression with the new one
For each ($expression;$_expressions)
  WP INSERT FORMULA($expression.range;$formula;wk replace)
End for each 

 

More improvements

Some existing expressions have also been improved and simplified. Reserved local variables like $wp_pageCount or $wp_author have now been declared obsolete even if they’re still supported. They’ve been replaced by using the more readable and modern This.property. Here’s the complete list of available properties:

$wp_subject   -> This.subject
$wp_author -> This.author
$wp_company   -> This.company
$wp_notes   -> This.notes
$wp_dateCreation   -> This.dateCreation
$wp_dateModified   -> This.dateModified
$wp_pageNumber   -> This.pageNumber
$wp_pageCount   -> This.pageCount
$wp_title   -> This.title

 

More powerful, more simple

To conclude, we’re sure that the use of these native commands will really simplify the way you manage formulas inside 4D Write Pro documents. Feel free to read the full documentation and have a look at the HDI database for more information!

Discuss

Tags 4D Write Pro, Formula, v18 R2, v19, Word processor

Latest related posts

  • November 14, 2025

    Event Report in 4D Qodly Pro: See Every Interactions at a Glance

  • November 14, 2025

    4D Qodly Pro: Page Zoom Controls

  • November 13, 2025

    macOS Tahoe, Windows 11, which operating systems for 4D 20 and 21?

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