Report.WordXmlPart([Boolean]) Method

Version: Available or changed with runtime version 1.0.

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

Syntax

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

Parameters

Report
 Type: Report
An instance of the Report data type.

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

Return Value

String
 Type: Text
A string representation of 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;
    MyReport: Report Report6;
begin
    ReportAsXmlString := MyReport.WordXmlPart();  
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>

See Also

Report Data Type
Get Started with AL
Developing Extensions