Export to XML file data from table 81

I am trying to export all recods from table 81 to a XML file, with this C/AL on DataItem Button.

IF “Elect. Pmts Exported” THEN
IF NOT CONFIRM(ExportAgainQst) THEN
EXIT;

//BankAccount.GET(GenJnlLine1.“Bal. Account No.”);
//GenJnlLine.SETRANGE(“Document No.”,“Document No.”);
GenJnlLine.SETCURRENTKEY(“Journal Template Name”,“Journal Batch Name”,“Line No.”);
GenJnlLine.SETRANGE(“Journal Template Name”,‘PAGAMENTOS’);
GenJnlLine.SETRANGE(“Journal Batch Name”,‘GESBA’);

//GenJnlLine.SETRANGE(“Document No.”,“Document No.”);
//GenJnlLine.“Bal. Account No.” := BankAccount.“No.”;

IF GenJnlLine.FINDSET THEN
REPEAT

GenJnlLine.SETRANGE(“Document No.”,GenJnlLine.“Document No.”);
MESSAGE(‘DOCNª m= %1’,“Document No.”);

// CODEUNIT.RUN(CODEUNIT::“SEPA CT-Export File”,GenJnlLine);
UNTIL GenJnlLine.NEXT = 0;

CODEUNIT.RUN(CODEUNIT::“SEPA CT-Export File”,GenJnlLine);

FIND;
“Elect. Pmts Exported” := TRUE;
MODIFY;

The XML file is generated, but only with the 81 table first Record.

Why is that, if I am using Repeat Until function?

Regards

The first question to ask is whether you want one export file for each line in the journal dataset (filtered by Document No.), or whether you want all of the lines in the filtered dataset in one export file. If you want one file per line, then you want to make the call to your codeunit within the repeat loop. If you want only one file, then call the codeunit outside of the repeat loop, as you’re doing now.

The next question has to do with whether, in the codeunit or xmlport, you are setting any additional filters on the record.

And just an observation … You’re filtering on Document No., but that field isn’t in the current key. Consequently, it’s possible that you’ll have a non-sequential list of Document No. values in the repeat loop. While you’ll eventually get all of the records using this construction, the possibility of duplicating exported lines exists. To clean that up, create or use a key that begins with Document No.

Hello George

I pretend only one file with all my recods in Table 81. Each line in jornal represents one document. I waan all of them in the same xmlport.

I am callig my codeunit outside the Loop. I think it is OK …

I created a new Key, Document No in table 81. But how can I change the order in a Key? The other keys must be as they are.

In CU I am doing this:

OnRun(VAR Rec : Record “Gen. Journal Line”)
LOCKTABLE;
//BankAccount.GET(“Bal. Account No.”);
//GenJournalLine.GET();

IF Export(Rec,XMLPORT::“SEPA CT pain.001.001.03”,’’) <> ‘’ THEN

MODIFYALL(“Exported to Payment File”,TRUE);

Export(VAR GenJnlLine : Record “Gen. Journal Line”;XMLPortID : Integer;FileName : Text[1024]) : Text[1024]
TempBlob.INIT;

TempBlob.Blob.CREATEOUTSTREAM(OutStr);

XMLPORT.EXPORT(XMLPortID,OutStr,GenJnlLine);

//PostProcessXMLDocument(TempBlob);

IF FileName = ‘’ THEN
FileName := FileManagement.BLOBExport(TempBlob,STRSUBSTNO(’%1.xml’,GenJnlLine.GETFILTER(“Document No.”)),TRUE)
//FileName := FileManagement.BLOBExport(TempBlob,STRSUBSTNO(’%1.xml’,GenJnlLine.“Posting Date”),TRUE)
ELSE
FileName := FileManagement.BLOBExport(TempBlob,FileName,FALSE);
EXIT(FileName);

PostProcessXMLDocument(VAR TempBlob : Record TempBlob)
CREATE(XMLDoc);
TempBlob.Blob.CREATEINSTREAM(InStr);

XMLDoc.load(InStr);
XMLNode := XMLDoc.documentElement;

DeleteEmptyXMLNodes(XMLNode);

CLEAR(TempBlob);
TempBlob.Blob.CREATEOUTSTREAM(OutStr);
XMLDoc.save(OutStr);

DeleteEmptyXMLNodes(VAR XMLNode : Automation “‘Microsoft XML, v3.0’.IXMLDOMNode”)
IF XMLNode.nodeTypeString = ‘element’ THEN BEGIN
IF NOT XMLNode.hasChildNodes THEN BEGIN
IF (XMLNode.xml = ‘<’ + XMLNode.nodeName + ’ xmlns="’ + XMLNode.namespaceURI + ‘"/>’) THEN
XMLNode := XMLNode.parentNode.removeChild(XMLNode);
END ELSE BEGIN
XMLDomNodeList := XMLNode.childNodes;
FOR i := 1 TO XMLDomNodeList.length DO BEGIN
XMLChildNode := XMLDomNodeList.nextNode();
DeleteEmptyXMLNodes(XMLChildNode);
END;
IF NOT XMLNode.hasChildNodes THEN
XMLNode := XMLNode.parentNode.removeChild(XMLNode);
END;
END;

Thanks

Hello George…Any idear about this?

Well, from your code, you’ve got a lot going on here. When I’m trying to resolve something like this, I like to go back to basics. I’d suggest that you start a parallel project - leave these current objects alone for a while. Make a straight xmlport object that runs against table 81 and that includes the fields that you want to export. Don’t embellish, just make a simple object. Then build a simple codeunit from which to launch the xmlport. Again, very simple. Don’t worry about filters or anything like that. Once you get that working, then you can build on it.