CVAL() Function

YouTube: How to Use the CVAL () Function in Report Custom Columns?arrow-up-right

How to Use the CVAL () Function in Report Custom Columns?

In this tutorial, we will learn how to use the CVAL function to convert string or text-based numeric values into decimal numbers, enabling accurate mathematical calculations in reports.


Accessing the Expression Designer:

  • Navigate to the Reporting section.

  • Open the Sales Register Detailed Report or any "Report".

  • Go to Setup Column Attributes.

  • Here, you'll see a list of available columns that can be used to build expressions.

  • Click on "Add/Edit Expression Columns" where you can write your expression using predefined functions.

  • Before adding the expression to the report, go to Other Settings.

  • Ensure the Script Editor is set to VBScript.

  • Click Save.

    • Note: VBScript is the default for new configurations but always verify this setting.

Writing Your First Expression

  • Every expression must start with the script header: '#@LSCRIPT

  • Click the (+) Plus icon to create a new expression.

  • Fill in the required fields:

    • Expression Name – A unique name for your expression.

    • Expression Type – Choose either Text or Numeric depending on the expected output.

Creating a Simple CVAL() Expression

  • Double-click the new expression name to insert it into the script editor.

  • Define the expression using the syntax:

    • Expression Name = CVAL('TOTAL_QTY')

      • CVAL converts the value to a decimal, which can then be used for calculations like sums or averages.

      • Replace 'TOT_QTY' with the string-based field you want to convert (keep the field name in single quotes).

  • Save the expression once defined.

  • Scroll down and check the box beside the expression name to enable it.

  • Save and proceed to check the effect.

  • Refresh the report to view the final result.


Output:

Item Name
TOT_QTY (Text)
CVAL Expression Result

Item A

"10.50"

10.50

Item B

"25"

25

With the CVAL function, the system can now treat these as numeric values in totals, filters, or other numeric expressions.

Last updated