Exporting comments in XMLPort

bhalpinbhalpin Member Posts: 309
Hi.

I am trying to configure an XMLPort to export posted whse shipments (Transfer Shipment Header and and associated Transfer Shipment Lines).

The lines export as expected, but I am having trouble with the comments attached to the header. The format I want to obtain is:
...
<Comments>
  <Comment>Comment 1</Comment>
  <Comment>Comment 2</Comment>
  ...
  <Comment>Comment n</Comment>
</Comments>
...

In the report designer, I have:
Shipment
  Element
  Table
  TransShipHeader(Transfer Shipment Header)
  ...
  Comments
    Element
    Table
    InventoryCommentLine(Inventory Comment Line)
    SourceTableView: WHERE(Document Type=CONST(Posted Transfer Shipment))
    LinkTable: TransShipHeader
    LinkFields: No.=FIELD(No.)
    MinOccurs: Zero
    MaxOccurs: Once
    Comment
      Element
      Field 
      InventoryCommentLine::Comment
      MinOccurs: Zero
      MaxOccurs: Unbounded

The result I am getting is only the 1st comment line:
<Comments>
    <Comment>Comment 1</Comment>
</Comments>

Can anyone point out where I'm going wrong? ](*,)

Thanks' in advance.

Bob

Comments

  • DenSterDenSter Member Posts: 8,305
    Hi Bob, it seems to be your MaxOccurs property
    bhalpin wrote:
    In the report designer, I have:
        MaxOccurs: Once
    
  • bhalpinbhalpin Member Posts: 309
    Hi.

    Thank's, but if I set the MaxOccurs on 'Comments' to Unbounded, I get this:
    <Comments>
      <Comment>Comment 1</Comment>
    </Comments>
    <Comments>
      <Comment>Comment 2</Comment>
    </Comments>
    <Comments>
      <Comment>Comment 3</Comment>
    </Comments>
    

    ?????

    Bob
  • XypherXypher Member Posts: 297
    DenSter wrote:
    Hi Bob, it seems to be your MaxOccurs property
    The property you're looking at is for the 'Comments' node which he wont want to be repetitive.


    The issue I believe is Navision doesn't allow multiple of the same elements when exporting, but it will do this fine when importing. I suppose it just does not know how to interpret it.

    The only way I can see you being able to do this is to do the following:
      1) Remove the 'Comment' element within the 'Comments' node 2) Export the XMLport to a Stream to be manipulated using the MSXML Automation
      a) Export to a Temporary Blob b) Load via Stream to XML Dom Document
    3) Cycle through the InventoryCommentLine (with applied filters) and add each Comment line using the automation
    4) And finally exporting to file (which can be easily done using the automation; XMLDom.save('C:\Path\File.xml'))

    If you would like some sample code let me know and I'll whip some up for you.

    (You can download the latest version of MSXML at this link.)
  • bhalpinbhalpin Member Posts: 309
    Hi Xypher.

    Yikes!

    Before posting this topic I searched the forum and saw this stuff mentioned.

    Before jumping off that cliff thouhg, there's got to be an easier way to get the comments out. As it stands, the specs for the receiving end of this file are not defined yet - so I'm pretty free to set the output format as I like. Would you see anything wrong (XML-wise) with this:
    ...
    <Comments>
      Comment Line 1
    Comment Line 2
    ...
    Comment Line n
    </Comments>
    

    If that looks kosher, then I guess my next question is how to produce it.

    Is this the right track:

    - Change Comments to Element, Text

    - In Comments - Export::OnBeforePassVariable()
    - Define a local record variable for the comments table
    - Set filters to get the ones I want
    - Iterate through the records, appending the text to Comments

    What do you think?

    Bob
  • XypherXypher Member Posts: 297
    You cannot dynamically manipulate elements in XMLports. Sorry :(
  • bhalpinbhalpin Member Posts: 309
    Sorry Xypher,

    too late - I tried it:

    (Comments, Element, Text)
    Comments - Export::OnBeforePassVariable()
    Comments := '';
    InvComments.SETFILTER("Document Type",'Posted Transfer Shipment');
    InvComments.SETFILTER("No.",TransShipHeader."No.");
    IF InvComments.FINDSET THEN BEGIN
      REPEAT
        Comments := NewComments + InvComments.Comment;
      UNTIL InvComments.NEXT = 0;
    END;
    

    In the output file, I get:
    <NewComments>Comment 1Comment 2Comment3</NewComments>
    

    What do you think?

    Bob
  • XypherXypher Member Posts: 297
    You're not creating individual comment elements with that code. All I see is adjusting the output for NewComments element.

    But if that will work for you then sure go for it.
  • bhalpinbhalpin Member Posts: 309
    It works for me - as long as I get all the comments out the format is not critical.

    Also, the code in my prior post was wrong. NewComments was the name I used for testing, and I didn't edit all the occurances to 'Comment' before posting. The code should read:
    Comments - Export::OnBeforePassVariable() 
    Comments := ''; 
    InvComments.SETFILTER("Document Type",'Posted Transfer Shipment'); 
    InvComments.SETFILTER("No.",TransShipHeader."No."); 
    IF InvComments.FINDSET THEN BEGIN 
      REPEAT 
        Comments := Comments + InvComments.Comment; 
      UNTIL InvComments.NEXT = 0; 
    END;
    

    and the output:
    <Comments>Comment 1Comment 2Comment3</Comments>
    

    Thank's for your help Xypher.

    Bob
  • XypherXypher Member Posts: 297
    With the code you provided, you may very easily run into 1024 buffer overflow with the Comments variable.

    I would recommend switching from DataType: Text to BigText and do the following,
    Comments - Export::OnBeforePassVariable()
      //Don't need to initialize/clear the value if you don't assign a table/field to the element
      InvComments.SETRANGE("Document Type",'Posted Transfer Shipment');
      InvComments.SETRANGE("No.",TransShipHeader."No.");
    
      IF InvComments.FINDSET THEN
        REPEAT
          Comments.ADDTEXT(InvComments.Comment);
        UNTIL InvComments.NEXT = 0;
    
  • bhalpinbhalpin Member Posts: 309
    Thank's (again!)

    I had seen that coming, but hadn't gone after it yet.

    Right now I'm wrestling with trying to add Lot No. information elements to each line item. What a swamp!

    I've looked at the way the info is assembled:

    Table 5745: Transfer Shipment Line.ShowItemTrackingLines(), calls:

    Codeunit 6500: Item Tracking Management.CallPostedItemTrackingForm(DATABASE::"Transfer Shipment Line",0,"Document No.",'',0,"Line No.");

    CallPostedItemTrackingForm creates a a temporary Item Ledger Entry table, and then calls Item Tracking Management.RetrieveILEFromShptRcpt(), passing it the table to be filled up with the Lot No lines.

    Looks easy enough to use/steal/copy/whatever. But - I think there's a(nother) brick wall coming because I haven't found a way to use a temporary table as the data source for an XML port.

    Do you think there's an easier way to find/export the lot no information?

    Bob
  • XypherXypher Member Posts: 297
    You can always declare the temporary table as a local variable (without needing to assign table/field properties to element(s)) construct the temporary table and loop through the records in whichever fashion you need whilst assigning the fields.

    Other than that I don't really know what is involved with "Lot No. Information", I'm just a Jr. Programmer.
  • DenSterDenSter Member Posts: 8,305
    bhalpin wrote:
    Hi.

    Thank's, but if I set the MaxOccurs on 'Comments' to Unbounded, I get this:
    Sorry, I had my eyes crooked... Try binding the Comment node to the comment table, instead of the Comments node. That way you can leave the maxoccurs of Comments to 1, and it should repeat as many times as there are records in the comment node.

    I kind of lost track of this thread, but it should be possible to make this work.
Sign In or Register to comment.