Replace ( ) Function

YouTube: How to Use the Replace ( ) Function in Report Custom Columns?

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

In this tutorial, you will learn how to use the REPLACE function to modify text in a data column. This function allows you to dynamically replace specific text patterns within a field, both in the data grid and within a report.


Accessing the Expression Designer:

  • Open Sale Voucher or any document.

  • Navigate to the "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.

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.

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

  • Define the expression using the syntax:

    • Expression Name = REPLACE("ITEM_CODE", "ARR", "COD")

  • Click Save after writing the expression.

  • Scroll down and check the box to enable the column.

  • Save and proceed to check the effect.

  • Scan or display items where the ITEM_CODE contains the string ARR.

  • You’ll notice that all instances of ARR are now replaced by COD in the new column.


Applying the Expression in a Report

  • Navigate to the Reporting section.

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

  • Go to Setup Column Attributes as you did earlier.

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


Adding and Using the Expression in the Report

  • Return to "Setup Column Attribute" window.

  • Click "Add/Edit Expression Columns".

  • 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 REPLACE() Expression

  • Double-click your newly created expression to insert it into the script editor.

  • Define the expression using the syntax:

    • Expression Name = REPLACE("ITEM_CODE", "ARR", "COD")

    • "Item Code" is the source field.

    • "ARR" is the current item code.

    • "COD" is what we want to replace it with.

  • Click Save.

  • Scroll down and check the box to enable the column in the report.

  • Save and proceed to check the effect.

  • Refresh the report to view the final result.

  • You’ll notice that all instances of ARR are now replaced by COD in the new column.


Summary: What You Achieved

  • You learned how to use the REPLACE function in both data grids and reports.

  • You saw how to replace any substring in a text field dynamically.

  • You confirmed how the function behaves if the target text isn’t found (i.e., the original value is retained).

Last updated