Compartilhar via


WORDXMLPART Function

Returns the report data structure as structured XML that is compatible with Microsoft Word custom XML parts.

The function has an instance call and a static call. The following code shows the syntax of the WORDXMLPART function. The first line of code is the syntax for an instance function call. The second line of code is the syntax for a static function call.

String := ReportVariable.WORDXMLPART([ExtendedFormat])

String := REPORT.WORDXMLPART(Number[, ExtendedFormat])

Parameters

  • ExtendedFormat
    Type: String If you set this variable to true, then XML elements will include the following attributes attributes:

    • ElementType="Parameter|Column|DataItem"

      Specifies the element type as defined for the report in Report Designer. Parameter is typically used for elements, such as captions.

    • ElementId="ID"

      Specifies the ID that is assigned to the element by its ID Property.

    • DataType="Type"

      Specifies the Microsoft Dynamics NAV data type of the element.

    If you omit this parameter or set it to false, then the element attributes are not included in the XML. This is the recommended setting when you will use the Word XML part in Word for modifying the report layout because the XML is simpler. The following example illustrates an XML element that has the ExtendedFormat set to false: <CompanyName ElementType="Column" ElementId="3" DataType="OemText"> The following example illustrates the same XML with the ExtendedFormat set to true: <CompanyName>

  • Number
    Type: Integer The ID of the report that you want to run. From the C/AL Editor, on the View menu, choose C/AL Symbol Menu to select the report from a list. If the report you specify does not exist, then a run-time error occurs.

Return Value

Type: Text

You must use the return value; otherwise you cannot compile the object.

Remarks

This function returns the data structure of the report as structured XML that complies with custom XML parts in Microsoft Word 2013. The following table provides a simplified overview of the XML that is returned by the function.

XML Description

<?xml version="1.0" encoding="utf-16"?>

Header

<NavWordReportXmlPart xmlns="urn:microsoft-dynamics-nav/report/<reportname>/<id>/"

XML namespace specification. <reportname> is the name assigned to the report object in Microsoft Dynamics NAV Development Environment. <id> is the ID that is assigned to the report.

..<Labels>

....<ColumnNameCaption>ColumnNameCaption</ColumnNameCaption>

....<LabelName>LabelCaption</LabelName>

..</Labels>

Contains all the labels for the report. Labels are listed in alphabetical. The element includes labels that are related to columns that have the IncludeCaption Property set to Yes and labels that are defined in Report Label Designer.

  • Label elements that are related to columns have the format <ColumnNameCaption>ColumnNameCaption</ColumnNameCaption>, where ColumnName is determined by the column's Name Property.

  • Label elements from Report Label Designer have the format <LabelName>LabelCaption</LableName, where LabelName is determined by the label's Name Property and LabelCaption is determined by the label's Caption Property.

..<DataItem1>

....<DataItem1Column1>DataItem1Column1</DataItem1Column1>

Top-level data item and columns. Columns are listed in alphabetical order.

The element names and values are determined by the Name property of the data item or column.

....<DataItem2>

......<DataItem2Column1>DataItem2Column1</DataItem2Column1>

....</DataItem2>

....<DataItem3>

......<DataItem3Column1>DataItem3Column1</DataItem3Column1>

....</DataItem3>

Data items and columns that are nested in the top-level data item. Columns are listed in alphabetical order under the respective data item.

..</DataItem1>

</NavWordReportXmlPart>

Closing elements.

Word custom XML parts enable you to integrate business data into Word documents. For example, the WORDXMLPART function is used internally by Microsoft Dynamics NAV when you are creating report layouts in Word. You can use this function to create a custom XML part, and then, together with the SAVEASXML Function (Reports) function and additional data merging tools, you can implement your own functionality for mapping and laying out report data in Word documents. To create a custom XML part, you can save the return value to an .xml file that is encoded in UTF-16 (16-bit Unicode Transformation Format). The resultant file can be added to Word documents as a custom XML part to map the report data set as XML data.

Example

The following example uses the WORDXMLPART function to save the data structure of Report 112 Sales Statistics in an XML file that can be added to Word as a custom XML part. This example requires that you have a blank text file that is named SalesStatsReport.xml and located in the C:\Report Documents folder. You must also create the following variables in the C/AL Globals window.

Variable DataType

ReportAsString

Text

SalesStatsReport

File

String := REPORT.WORDXMLPART(112);
SalesStatsReport.TEXTMODE(TRUE);
SalesStatsReport.WRITEMODE(TRUE);
SalesStatsReport.OPEN('C:\Report Documents\SalesStatsReport.xml', TextEncoding::UTF16);
SalesStatsReport.WRITE(String);
SalesStatsReport.CLOSE;

The code generates the report structure as XML, and then writes the XML to the file C:\Report Documents\SalesStatsReport.xml.

See Also

Concepts

Designing Word Report Layouts