XML Ports with Format Property - Variable Text

apickardapickard Member Posts: 42
edited 2010-08-19 in NAV Three Tier
Hi all,

in Dynamics NAV 2009, if you set an XML port to be used in RTC with Format property set to Variable text, is it possible to create dependent nodes in the same XML dataport of type table? :-k

I'm asking this question as I tried to create such nodes (eg. Customer and Customer ledger entry) and the following error is being displayed: "An element with source type Table cannot have Table element children".

If Format property is changed to XML, this same setup works correctly.

Any ideas how this can be solved!!

Comments

  • kinekine Member Posts: 12,562
    You can include another table, but you need to nest it into some text attribute to have structure like:
    Customer - table
      CustomerLedgerEntries - text
        CustomerLedgerEntry - table
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • apickardapickard Member Posts: 42
    Hi Kamil,
    first of all thanks for your reply. However when I tried this option the system displayed the following error: "If element has source type table, then it cannot have grandchildren". What I tried was:

    Customer - element - table - Indentation1
    CustLedEntries - ( both attribute and element) - text - Indentation2
    CustLedEntry - element - table - Indentation3

    I've also tried other alternatives without any success. These errors do show up only when the XML Port format property is set to either Variable Text or Fixed Text!!

    Am I doing something wrong?
  • apickardapickard Member Posts: 42
    Hi all,

    any ideas about this issue #-o

    Are xml ports with the new format property being used extensively??

    Thanks for all suggestions
  • dmc-dkdmc-dk Member Posts: 42
    Hi everybody,

    Bumped into the same problem! Even more - VariableText and FixedText formats are not working when you run XMLPorts from Classic Client - so you have to call the XMLPort from RTC to make sure it exports data in those formats.
    But I *almost* made it work by implementing the structure in the attachment. I built it on two Integer tables and doing all filtering and navigation through recordsets in C/AL at OnPreXMLItem and OnAfterGetRecord triggers.

    First Integer table has SourceTableView set to WHERE(Number=CONST(1)) second - not limited.

    The reason I am saying *almost* - still need to debug C/AL part to make it work properly for all scenarios - have a couple of minor glitches there. But I have to run now - so I am giving you what I have so you could play with it if it is urgent. Otherwise - I will post working example on Monday.
  • dmc-dkdmc-dk Member Posts: 42
    I've finished the example and here is what I ended up with (unfortunately cannot attach .fob here):

    Codeunit XML Port Runner
    OnRun()
    Path := 'd:\Invoices.txt';
    SalesDocumentNo := '101015';
    
    IF EXISTS(Path) THEN
      ERASE(Path);
    
    DataFile.WRITEMODE(TRUE);
    DataFile.TEXTMODE(TRUE);
    DataFile.CREATE(Path);
    DataFile.CLOSE; //Needed for RTC
    DataFile.OPEN(Path);
    
    ExportSalesOrder.SetSalesHeader(SalesDocumentNo); // Sets the Sales Header to be exported
    DataFile.CREATEOUTSTREAM(XMLOutStream);
    ExportSalesOrder.SETDESTINATION(XMLOutStream);
    ExportSalesOrder.EXPORT;
    
    DataFile.CLOSE;
    MESSAGE('Done!')
    

    XML Port Export Sales Order (Format: FixedText, all Width properties for the fields are set to 10)
    PROCEDURE SetSalesHeader(DocumentNo : Code[20])
    SH.GET(SH."Document Type"::Order,DocumentNo)
    
    IntegerSalesLine - Export::OnPreXMLItem()
    SL.SETRANGE("Document Type",SH."Document Type");
    SL.SETRANGE("Document No.",SH."No.");
    IF NOT SL.FINDSET THEN
      currXMLport.QUIT;
    
    NoOfRecords := SL.COUNT;
    CurrentRecNo := 0;
    
    IntegerSalesLine - Export::OnAfterGetRecord()
    CurrentRecNo := CurrentRecNo + 1;
    IF NOT (CurrentRecNo = 1) THEN BEGIN
      IF CurrentRecNo > NoOfRecords THEN
        currXMLport.QUIT
      ELSE
        SL.NEXT;
    END
    


    And code lines like these at all Export::OnBeforePassVariable triggets:
    Header_No. - Export::OnBeforePassVariable()
    "Header_No." := SH."No.";
    
    Line_Line_No. - Export::OnBeforePassVariable()
    "Line_Line_No." := FORMAT(SL."Line No.");
    

    And here is what I get when I run this codeunit from RTC:
    101015    49633663  Autohaus M
    
    10000     Item      1972-S    MUNICH Swi
    20000     Item      1968-S    MEXICO Swi
    30000     Item      1896-S    ATHENS Des
    40000     Item      1906-S    ATHENS Mob
    

    Best regards,
    DMC
  • dmc-dkdmc-dk Member Posts: 42
    It appears that things can be done much easier when "upgrading" a dataport to XMLPort object. You don't have to use Integer table to navigate through header and lines, you can actually use the tables themselves – just like you could with dataports.
    And since you cannot indent Dataitems, you have to filter the lines at OnPreXMLItem trigger. In my example I use Source Type = Text, but Field is also supported.
    Below you can see the settings I used for an XMLPort with Variable Text format (semicolon separated) – they are quite different from default.
Sign In or Register to comment.