Microsoft Dynamics 365 Blog

For those that have not used this before, the Style Sheet Tool is a free code sample used as an addition to standard Dynamics NAV application, for enhancing send-to Word functionality on Dynamics NAV by allowing simple and user-friendly style sheet customization. After lots of feedback form partners, I have added an extra dimension to this tool: the ability to export several tables with multiple records. Up to now, any number of tables was allowed provided they all show one record each, in addition to one table showing multiple records.

This ’constraint’ is now removed, or rather, the design is adjusted to allow several tables showing multiple records each, to be included in merge document design.

To align the tool with this extension, the following code needs to be replaced:

Codeunit 680 : Style Sheet Management

Global variables: add following two variables to the list of global variables of this codeunit

Name                                            DataType

NoOfMultiLineTables                     Integer

MLCounter                                    Integer

ManageMultiLineChanges trigger   (this code change applies to all versions of the tool)

Old Code: 

RemoveEndOfMultiLine(NodeTextValue);

EXIT(Return);

New Code:

RemoveEndOfMultiLine(NodeTextValue);

// EXIT(Return);                           //changed line

CreateMultilLineSection trigger (the code marked as old code here differs a bit in different versions of the tool. The essence of the change is still the same, MLCounter is to be ‘started’ at the beginning of this trigger)

Old Code:

// Create section for Multi-Lines

ChildNode := IOChildNode.parentNode;

New Code:

// Counter for multiple multiline sections //added line

MLCounter +=1;                             //added line

// Create section for Multi-Lines

ChildNode := IOChildNode.parentNode;

CreateMultiLineBody trigger

Local variables: the following local variable is added to the trigger

Name

DataType

MultilineEnd

Boolean

(the code marked as old code below differs a bit in different versions of the tool, and this line is called in several triggers in some versions of the tool. The essence of the change is though the same:

EACH references to  multiline-section-properties (contained within this line: LoadAttributes(1,’name’,’multiline-section-properties’);)

should be replaced with  LoadAttributes(1,’name’,’multiline-section-properties’+FORMAT(MLCounter)) as that creates unique references to different multi-line sections by adding a counter to the end of each, where there previously was only ONE, called multiline-section-properties

The example below is from version 1.1

Old Code:

ParentNode := ChildNode.parentNode;

LoadAttributes(1,’name’,’multiline-section-properties’);

AddElement(ParentNode,NewChildNode,Text043,1);

New Code:

ParentNode := ChildNode.parentNode;

// Add counter to multiline section name, for unique reference         // added line

LoadAttributes(1,’name’,’multiline-section-properties’+FORMAT(MLCounter)); //changed line

AddElement(ParentNode,NewChildNode,Text043,1);

The following code change applies to all versions fo the tool:

Old Code:

ChildNodeList := ParentNode.childNodes;

FOR NodeCount := 1 TO ChildNodeList.length DO BEGIN

  ChildNode := ChildNodeList.item(NodeCount – 1);

  TempNodeName := ChildNode.nodeName;

  IF TempNodeName = Text043 THEN

    MultiLineNodeCount[1] := NodeCount;

  TempNodeValue := GetTextNodeValue(ChildNode);

  IF TempNodeValue <> ” THEN

    MultiLineNodeCount[2] := NodeCount – 1;

END;

// If MULTILINE_END is not found then set end to number of nodes.

IF MultiLineNodeCount[2] = 0 THEN

  MultiLineNodeCount[2] := NodeCount;

New Code:

ChildNodeList := ParentNode.childNodes;

NodeCount := 1;                                            //added line

WHILE (NodeCount <= ChildNodeList.length) AND

      (NOT MultilineEnd) DO BEGIN                          //changed line

// exit the loop when next multiline end is found          //added line

  ChildNode := ChildNodeList.item(NodeCount – 1);

  TempNodeName := ChildNode.nodeName;

  IF TempNodeName = Text043 THEN BEGIN                     //changed line

    MultiLineNodeCount[1] := NodeCount;

  END;

  TempNodeValue := GetTextNodeValue(ChildNode);

  IF TempNodeValue <> ” THEN BEGIN                        //changed line

    IF STRPOS(TempNodeValue,Text021) <> 0 THEN

      MultilineEnd := TRUE;                                //added line

    MultiLineNodeCount[2] := NodeCount – 1;

  END;                                                     //added line

  NodeCount +=1;                                           //added line

END;

IF NodeCount <= ChildNodeList.length THEN

  NodeCount := NodeCount -1;                               //added line

MultilineEnd := FALSE;                                     //added line

// If MULTILINE_END is not found then set end to number of nodes.

IF MultiLineNodeCount[2] = 0 THEN

  MultiLineNodeCount[2] := NodeCount;

The following code change applies to all versions fo the tool:

RemoveEndOfMultiline Trigger

Old Code:

// Remove end node of Multi-Lines

ChildNodeList := XMLDoc.getElementsByTagName(‘w:r’);

FOR NodeCount := 1 TO ChildNodeList.length DO BEGIN

  ChildNode := ChildNodeList.item(NodeCount – 1);

  ParentNode := ChildNode.parentNode;

  IF STRPOS(GetTextNodeValue(ChildNode),Text021) <> 0 THEN BEGIN

    ParentNode.removeChild(ChildNode);

    EXIT;

  END;

END;

New Code:

Add the following parameter to this trigger:

Name                        DataType    Length

NodeTextValue  Text     250    

// Remove end node of Multi-Lines

// nodetextvalue = multiline_begin_tablename

NodeTextValue := COPYSTR(NodeTextValue,17,MAXSTRLEN(NodeTextValue));  //added line

ChildNodeList := XMLDoc.getElementsByTagName(‘w:r’);

FOR NodeCount := 1 TO ChildNodeList.length DO BEGIN

  ChildNode := ChildNodeList.item(NodeCount – 1);

  ParentNode := ChildNode.parentNode;

  IF STRPOS(GetTextNodeValue(ChildNode),Text021) <> 0 THEN BEGIN

  //Check if this is the right MULTILINE_END to remove                // added line

    IF STRPOS(GetTextNodeValue(ChildNode),Text021+’_’+NodeTextValue) <>0 THEN //added line

      ParentNode.removeChild(ChildNode);

  // EXIT; // remove all ends                                        //changed line

  END;

END;

Replace all occurences of the call to this trigger in the code:

RemoveEndOfMultiline;

 with

RemoveEndOfMultiline(NodeTextValue);

The extended codeunit 680 object is also attached.

Note: Code changes described apply to all versions of the tool, the codeunit attached applies to version 1.1 

You can direct your questions or feedback to jthunes@microsoft.com

Codeunit680.txt

We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!