Store data and use that data for calculations

Overview

Create a table that can store number data. These numbers can then be used to calculate other values.

Ingredients

App

Scaffolding

Macro

Table Data

Guide

Step 1 - Create a table

  1. Insert a Table Data macro and name it purchaseTable.

  2. Edit the parameters and set Initial Rows as 1.

  3. Create a 4x2 table inside the Table Data macro.

  4. Add the following names in the header row:

Item

Unit Price

Quantity

Total Price

Item

Unit Price

Quantity

Total Price









  1. Insert a Text Data, Number Data and Evaluate Data macro respectively into each table cell under each header as shown:



For this example, add the following names for each macro

  • Text Data: item

  • Number Data: unitPrice

  • Number Data: quantity

  • Evaluate Data: totalPrice

  1. Type the following code in the Evaluate Data macro:

${unitPrice} * ${quantity}

The macro looks as shown:

Step 2 - Add hidden stored data

  1. Create a Hidden Data macro under the Table Data macro created in the above section.

The Hidden Data macro is used when you want to enter data to be hidden from the reader of the page.

  1. Add two Number Data macros in the Hidden Data macro.

    1. Name them discount and tax.

    2. Set Allow Decimal Values as true for both macros as shown:

Step 3 - Add calculations

Let’s use Scaffolding to do some math and calculate the following:

  • Net Total (excluding tax and discount)

  • Discount Amount

  • Tax Amount

  • Grand Total (including tax and discount) 

  1. Add four Evaluate Data macros for each of the values above and give them relevant names, as below.

  2. Enter the following in the Display Format properties for each Evaluate Data macro:

$ #,##0.00
  1. Type the following codes into the respective Evaluate Data macros:

  • Net Total

    sumtable("purchaseTable","totalPrice")
  • Discount Amount

  • Tax Amount

  • Grand Total


The Evaluate Data macros must look similar to the following image:


  1. Save the page

  2. Click Edit Contents and in the Hidden Data macro:

    1. Input the value 10 for the Discount percentage field.

    2. Input the value 0.5 for the Tax percentage field.

  3. Click Publish.

Result