في هذه المقالة

X++ compile-time functions

11/03/2017

تستغرق القراءة 32 دقائق

المساهمون

في هذه المقالة

This topic lists the compile-time functions and describes their syntax, parameters, and return values.

Overview

Compile-time functions are executed early during compilation of X++ code. They should be used wherever possible in X++ code to make the code resilient to changes to the metadata stored in the Application Explorer. Compile-time functions have their input value verified by the compiler. If the input value is not found to match any existing object in the Application Explorer, the compiler issues an error. The inputs to these functions must be literals, because the compiler cannot determine the value that a variable contains at run time. A compile-time function is a metadata assertion function. It takes arguments that represents an entity in the Application Explorer and validates the arguments at compile time. It has no effect at run time. Attributes are classes that inherit from the SysAttribute class. To support the validation of form, report, query, and menu metadata, use the AutoDeclaration property on controls. Most of these functions retrieve metadata about items that are in the Application Explorer. Some common compile time functions are as follows:

classNum – Retrieves the ID of a class.

classStr – During compile time, verifies that a class of that name exists. This approach is better than discovering the error later during run time.

evalBuf– Evaluates the input string of X++ code, and then returns the results as a string.

literalStr – retrieves a label ID when given the string representation of a label, such as the string "@SYS12345". For example, myLabel.exists(literalStr("@SYS12345"));.

Note

X++ compile time functions cannot be called from a .NET program.

Functions

attributeStr

Validates that the specified attribute class exists in the Application Explorer; if not, a compiler error occurs.

Remarks

Example

classStr

Retrieves the name of a class as a string.

Syntax

str classStr(class class)

Parameters

Parameter

Description

class

The name of the class to return.

Return Value

The name of the class.

Remarks

Use this function instead of literal text to retrieve a string that contains the class name. If the class does not exist, the function generates a syntax error at compile time. This is a compile-time function. For more information, see Overview.

Example

configurationKeyStr

Syntax

str configurationKeyStr(str keyname)

Parameters

Parameter

Description

keyname

The name of the configuration key.

Return Value

The name of the configuration key.

Remarks

Use this function instead of literal text to retrieve a string that contains the configuration key name. If the key does not exist, the function generates a syntax error at compile time. This is a compile-time function. For more information, see Overview.

extendedTypeStr

Syntax

str extendedTypeStr(int str)

Parameters

Parameter

Description

str

The name of the extended data type.

Return Value

The name of the extended data type.

Remarks

Use this function instead of literal text to return a string that contains the extended data type name. If the data type does not exist, the extendedTypeStr function generates a syntax error at compile time. This is a compile-time function. For more information, see Overview.

formControlStr

Causes the X++ compiler to check whether the control exists on the form, and to replace the function call with a string of the valid control name.

Syntax

str formControlStr(formName, controlName)

Parameters

Parameter

Description

formName

The name of the form, not in quotation marks.

controlName

The name of the control that is on the form, not in quotation marks.

Return Value

A string that contains the name of the control as it appears in the Application Explorer.

Remarks

A compile error is issued if the compiler determines that the control does not exist on the form. If your X++ code uses a string that contains quotation marks to supply the control name, the error cannot be discovered until run time. Use of this function enables the compiler to discover the error earlier at compile time. X++ functions such as formControlStr that are executed by the compiler are called compile-time functions or compile-time functions. That is why the input parameters are not standard strings in quotation marks. Compile-time functions are not represented in the p-code or other executable that is output by the compiler. This is a compile-time function. For more information, see Overview.

identifierStr

Syntax

str identifierStr(str ident)

Parameters

Parameter

Description

ident

The identifier to convert.

Return Value

A string that represents the specified identifier.

Remarks

You will receive a best practice warning if you use the identifierStr function. This occurs because existence checking is performed for identifierStr. Try to use a more specific compile-time function if one is available. This is a compile-time function. For more information, Overview.

Example

The following code example assigns the myvar variable name to the thevar variable.

Return Value

Remarks

Example

queryDatasourceStr

Causes the X++ compiler to check whether the data source exists on the query, and to replace the function call with a string of the valid data source name.

Syntax

str queryDataSourceStr(queryName, dataSourceName)

Parameters

Parameter

Description

queryName

The name of the query, not in quotation marks.

dataSourceName

The name of the data source that is on the query, not in quotation marks.

Return Value

A string that contains the name of the data source as it appears in the Application Explorer.

Remarks

A compile error is issued if the compiler determines that the data source does not exist on the query. If your X++ code uses a string that contains quotation marks to supply the data source name, the error cannot be discovered until run time. Use of this function enables the compiler to discover the error earlier at compile time. X++ functions such as queryDataSourceStr that are executed by the compiler are referred to as compile-time functions or compile-time functions. That is why the input parameters are not standard strings in quotation marks. Compile-time functions are not represented in the p-code or other executable that is output by the compiler. This is a compile-time function. For more information, see Overview.

Return Value

Remarks

Example

ssrsReportStr

Retrieves a string that represents the name of the specified report. Use this function when you want to specify the report that should be run by a report controller class.

Syntax

str ssrsReportStr(str report, str design)

Parameters

Parameter

Description

report

The report to return the name for.

design

The name of the design that is associated with the report.

Return Value

The name of the report.

Remarks

The ssrsReportStr function parses the two values that are passed to it, to validate whether they belong to a valid report. The report name must be set when a menu item points to a controller(), so that the controller can determine which report-design combination must be invoked. Use of the ssrsReportStr function provides the benefit of compile-time validation for the report and design name. This is a compile-time function. For more information, see Overview.

Example

public static void main(Args _args)
{
// Initializing the object for a controller class, in this case, the class named AssetListingController.
SrsReportRunController controller = new AssetListingController();
// Getting the properties of the called object (in this case AssetListing MenuItem)
controller.parmArgs(_args);
// Setting the Report name for the controller.
controller.parmReportName(ssrsReportStr(AssetListing, Report));
// Initiate the report execution.
controller.startOperation();
}

Remarks

Example

workflowApprovalStr

Retrieves the name of a workflow approval in the Application Object Tree (Application Explorer) as a string.

Syntax

str workflowapprovalstr(approval approval)

Parameters

Parameter

Description

approval

The Application Explorer name of the workflow approval.

Return Value

A string that represents the Application Explorer name of the workflow approval.

Remarks

Use this function instead of literal text to retrieve a string that contains the workflow approval name. If the workflow approval does not exist, the function generates a syntax error at compile time. This is a compile-time function. For more information, see Overview.

Example

The following code example sets the variable str s to MyWorkflowApproval which is the name of the workflow approval in the Application Explorer.

workflowCategoryStr

Retrieves the name of a workflow category in the Application Object Tree (Application Explorer) as a string.

Syntax

str workflowcategorystr(category category)

Parameters

Parameter

Description

category

The Application Explorer name of the workflow category.

Return Value

A string that represents the Application Explorer name of the workflow category.

Remarks

Use this function instead of literal text to retrieve a string that contains the workflow category name. If the workflow category does not exist, the function generates a syntax error at compile time. This is a compile-time function. For more information, see Overview.

Example

The following code example sets the variable str s to MyWorkflowCategory which is the name of the workflow category in the Application Explorer.

workflowTaskStr

Retrieves the name of a workflow task in the Application Object Tree (Application Explorer) as a string.

Syntax

str workflowtaskstr(task task)

Parameters

Parameter

Description

task

The Application Explorer name of the workflow task.

Return Value

A string that represents the Application Explorer name of the workflow task.

Remarks

Use this function instead of literal text to retrieve a string that contains the workflow task name. If the workflow task does not exist, the function generates a syntax error at compile time. This is a compile-time function. For more information, see Overview.

Example

The following code example sets the variable str s to MyWorkflowTask which is the name of the workflow task in the Application Explorer.