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