Skip to content
🚀 Rapid Application Development with the App Builder

Use parent data in computed field

Parent data can be accessed in a detail table using the built-in function app.getParentData().

However, app.getParentData() is not available in all hooks, nor is it available in computed fields. To access parent data in a computed field, we can temporarily save the data in the postQuery hook and then use it in a computed field.

✨ Example postQuery

This code is executed in the postQuery hook of the detail table and saves the parent data to the variable window.parentData.

js
((table) => {

	window.parentData = app?.getParentData();

})

✨ Example Computed Field

Now the variable window.parentData can be used in a computed field.

js
Number(window.parentData?.["deptno"] ?? 0) * 0.03

📌 This must be a computed code field.

✨ Example onFormClose

Although not strictly necessary, it's good practice to clean up variables that are no longer used. The postQuery is added to the detail table and fires when the detail form is opened. The following code cleans up our temporary variable when the detail form is closed.

js
((mode, getColumnValue, setColumnValue, setColumnStyle, app) => {

	delete window.parentData;

})

📌 Important Note

This example uses JavaScript calculations. Please be aware that JavaScript calculations are not very reliable. JavaScript floating-point math can cause rounding errors. For critical calculations, use an external library like BigDecimal (see loadScript()) or multiply to work with integers.