Report.WordXmlPart(Integer [, Boolean]) Method

Version: Available or changed with runtime version 1.0.

Returns the report data structure as structured XML that is compatible with Microsoft Word custom XML parts. The method 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 method call. The second line of code is the syntax for a static method call.

Syntax

String :=   Report.WordXmlPart(Number: Integer [, ExtendedFormat: Boolean])

Parameters

Number
 Type: Integer
The ID of the report that you want to run. If the report you specify does not exist, then a run-time error occurs.

[Optional] ExtendedFormat
 Type: Boolean
If you set this variable to true, then XML elements will include the following 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 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 true: <CompanyName ElementType="Column" ElementId="3" DataType="OemText"> The following example illustrates the same XML with the ExtendedFormat set to false:<CompanyName>

Return Value

String
 Type: Text
The report data structure as structured XML that is compatible with Microsoft Word custom XML parts.

Remarks

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

XML Description
<?xml version="1.0" encoding="utf-16"?> Header
<NavWordReportXmlPart xmlns="urn:microsoft-../report/<reportname>/<id>/" XML namespace specification. <reportname> is the name assigned to the report object. <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 the labels section of the report.

- 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 the labels section of the report 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 method is used internally by Business Central when you are creating report layouts in Word. You can use this method to create a custom XML part, and then, together with the SaveAsXML Method (Reports) method 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 method to save the data structure of the report MyReport into a Text variable. The resultant string can be used in Word as a custom XML part.

report 50142 MyReport
{
    dataset
    {
        dataitem(MyDataitem; MyTable)
        {
            column(Field1; MyField)
            {
            }
        }
        dataitem(MySecondDataitem; MyTable42)
        {
            column(Field42; MyField42)
            {
            }
        }
    }

    labels
    {
        MyLabel = 'My Label Text';
        MySecondLabel = 'My Second Label Text';
    }

    ...
}
var
    ReportAsXmlString: Text;
begin
    ReportAsXmlString := MyReport.WordXmlPart(Report::MyReport);  
end;

The resulting XML then looks like this

<?xml version="1.0" encoding="utf-16"?>
    <NavWordReportXmlPart xmlns="urn:microsoft-dynamics-nav/reports/MyReport/50142">
        <Labels>
            <MyLabel>MyLabel</MyLabel>
            <MySecondLabel>MySecondLabel</MySecondLabel>    
        </Labels>
        <MyDataitem>
            <Field1>Field1</Field1>
        </MyDataitem>
        <MySecondDataitem>
            <Field42>Field42</Field42>
        </MySecondDataitem>    
    </NavWordReportXmlPart>

Note

The first parameter in WordXmlPart is an integer which represents the object ID of the report. To code robustly, never supply the object ID directly in your code. Instead, use the :: operator as illustrated in the example above. With this technique, if the report does not exist, you'll get a compile time error instead of a runtime error.

Report Data Type
Get Started with AL
Developing Extensions