4D Blog

Home Product 4D View Pro: Import callback ensures custom functions are fully resolved

4D View Pro: Import callback ensures custom functions are fully resolved

April 24, 2025

Product

Importing documents is a common task when working with 4D View Pro. However, when these documents contain custom functions, it can be challenging to determine when all calculations are completed before performing actions like printing or saving. To solve this, 4D 20 R9 makes sure that the callback formula of import commands is done only after all custom functions have been fully dealt with. This improvement gives more control and reliability when working with imported 4D View Pro documents.

HDI 4DVP End Loading Custom Function

The Updated Import Commands

The following import commands now guarantee that their callback is not executed until all custom functions have responded:

  • VP IMPORT DOCUMENT
  • VP IMPORT FORM BLOB
  • VP IMPORT FROM OBJECT

 

For example, if you’re loading a large document with many custom functions into an offscreen area, waiting for all calculations to finish, and then exporting it, you’ll need to set up a class like this:

property pdfPath : Text
property autoQuit:=False

Class constructor($pdfPath : Text)
   This.pdfPath:=$pdfPath
	
  // This function is called on each event for the offscreen area
Function onEvent
   Case of 
      : (FORM Event.code=On VP Ready)
         var $largeDocument4VP:="c:\\tmp\\mylargedocument.sjs"
			
         // Exports document in PDF called at the end of the import
         var $callback:=Formula(VP EXPORT DOCUMENT(This.area;\
            This.pdfPath; {formula: Formula(ACCEPT)}))
			
         // Document import with recalculation of all the formulas
         VP IMPORT DOCUMENT(This.area; $largeDocument4VP;\
            {formula: $callback; sjsOptions: {fullRecalc: True}})
			
			
      : (FORM Event.code=On URL Loading Error)
         CANCEL		
   End case 

and call it in your offscreen area:

// Creation of the offscreen parameter object to init the offscreen area
$offScreenParameter:=cs.OffScreenParameterClass.new($pdfPath)

// Creation of the offscreen area
VP Run offscreen area($offScreenParameter)

Update of VP FLUSH COMMANDS

We have also introduced a mechanism for waiting for the end of asynchronous calculations in the VP FLUSH COMMAND. In the same way as imports, you can now add a formula as a parameter which will be called at the end of calculations.

For example, if you add some calls to custom functions by programming and wait for their calculations to export the document:

// Adds an asynchronous calculation
VP SET FORMULA(VP Cell($area; 1; 2); "my4DFunction(1)")
// Waits for the calculation to finish and exports the document
VP FLUSH COMMANDS("ViewProArea"; Formula(VP EXPORT DOCUMENT("ViewProarea"; "c:\\tmp\\vpflush.xlsx")))

Conclusion

This update simplifies handling 4D View Pro imports with custom functions, making printing, saving, or processing documents easier only when all calculations are complete.

 

Discuss

Tags 20 R9, 21, 4D View Pro, Spreadsheet

Latest related posts

  • April 29, 2025

    Discover your AI-powered writing assistant in 4D Write Pro

  • April 28, 2025

    Unlock the Power of AI with 4D AIKit: Automate, Create, and Innovate

  • April 25, 2025

    Formulas in Label Wizard

Fabrice Mainguené
Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 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-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio 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