Skip to end of metadata
Go to start of metadata

Scripting allows you to write code and execute it at runtime when a report is generated. Backed with powerful scripting engine and it's comprehensive capabilities, almost all of business scenario can be achieved easily by using scripting. As it use c# style scripting, you can define any complex c# style statement and syntaxes on it. In general, scripting can be applied to event handlers and any properties of report components which support Expression. Besides that, scripting also can be used to customize the appearance of report components. Moreover, you have access to full .NET library and classes, you can get or set a property of an object, or even create new objects – all within the report scripting.

On this page:

This topic discusses some operations which can be done using ClientUI Scripting in the following sections.

Declaring Variable

Variable is a temporary container for storing data. The scope of a variable is the ReportPage within which it is defined. As with algebra, variable can be used to hold values (x=5) or expressions (z=x+y). Variable can have short names (like x and y) or more descriptive names (age, sum, totalPrice). The following rules must be considered when define a variable name.

  • The first character of variable name must be a letter.
  • Subsequent characters may be letters, underscore characters, or numbers.
  • The variable name is case-sensitive.

Variables is declared with the var keyword. The variable can hold a value of any data type. Unlike many other scripting languages, you don't have to tell what type of value the variable will hold during variable declaration. The value type of a variable can change during the report rendering and ClientUI scripting engine takes care of it automatically. See the following example.

C#

Formatting Text

String formatting is a capability to represent data in a number, currency, datetime, percentage, and other format. You can use String.Format method introduced in .NET library since you have access to full .NET library and classes. See the following code.

XAML

Some code snippets has been provided in expression editor to make it even easier to use at design time. 

Using Control Flow Statements

In general, scripts are executed from top to bottom, in the order that they appear. However, control flow statements break up the flow of execution by employing decision making, looping, and branching, enabling particular blocks of code to be executed conditionally.

  • For-Loop Statement
    For-Loop statement allows a block of code to be executed repeatedly.

    C#
  •  While Statement

    While statement allows a block of code to be executed repeatedly as long as the specified condition is true. 

    C#
  • If-Else Statement
    While statement allows a block of code to be executed when the specified condition is true.

    C#
  • Switch-Case Statement
    Switch-Case statement allow a block of code associated with the case to be executed when it is matched.

    C#

Using Special Variables

Special variables are predefined variables which is built into ClientUI Scripting and can be referenced while rendering report. You can retrieve information about the row number, page number, and etc.

Special VariableDescription
ColumnNumberReturns the current column number, which starts from 1.
RowNumberReturns the current row number, which starts from 1. Numbering for each group goes separately.
RowNumberThroughSimilar to RowNumber, but it ignores the groups in a report.
RowNumberABCReturns the current row number in alphabetical.
RowNumberRomanReturns the current row number in roman numeral.
GroupRowNumberReturns the current group line number, which starts from 1.
PageNumberReturns the current page number, which starts from 1.
PageNumberThroughSimilar to PageNumber, but it ignores ResetPageNumber property of ReportPage.
PageNofMReturns a string, displaying "Page N of M" where N is the current page number and M is the total pages of a report.
PageNofMThroughSimilar to PageNofM, but it ignores ResetPageNumber property of ReportPage.
TotalPageCountReturns the total pages of a report.
TotalPageCountThroughSimilar to TotalPageCount, but it ignores ResetPageNumber property of ReportPage.
IsFirstPageIndicating whether the current page is the first page.
IsFirstPageThroughSimilar to IsFirstPage, but it ignores ResetPageNumber property of ReportPage.
IsLastPageIndicating whether the current page is the last page.
IsLastPageThroughSimilar to IsLastPage, but it ignores ResetPageNumber property of ReportPage.

To use a special variable, you can define it like the following.

XAML

Some code snippets has been provided in expression editor to make it even easier to use at design time. 

Using Aggregate Functions

Aggregate Functions enable you to easily perform calculation on a set of values in the report. ClientUI Scripting supports the following aggregate functions.

Aggregate FunctionDescription
SumReturns the sum value of the specified conditions.
AvgReturns the average value of the specified conditions.
CountReturns the total rows.
MaxReturns the maximum value of the specified conditions.
MinReturns the minimum value of the specified conditions.

To use an aggregate functions, you can define it like the following.

XAML

Some code snippets has been provided in expression editor to make it even easier to use at design time. 

Using Math Functions

Since you have access to full .NET library and classes, you can easily use any mathematical functions introduced in .NET library. To use math functions, you can define it like the following code.

XAML

Some code snippets has been provided in expression editor to make it even easier to use at design time.

Accessing Report Document

In addition, you can use scripting to access any report data sources, components, and parameters. It can be easily achieved by using it's name. See the following example.

XAML
C#