Exported Output of a Dataport ...

Hi, Is there any way that I could export the purchase orders by separating the headers and lines into individual records, instead of exporting them as each record contains both header and line(or lines) using a dataport? I am currently using Purchase Line as the one and only dataitem. I tried using two dataitems: Purchase Header and Purchase Line, but it doesn’t seem to work, although I have all the dataport fields entered. Here is the current situation of the Output: Header of Order X; Line 10000 of Order X Header of Order X; Line 20000 of Order X Header of Order Y; Line 10000 of Order Y Header of Order Y; Line 20000 of Order Y Header of Order Y; Line 30000 of Order Y The Output that I am looking for is: Header of Order X; Line 10000 of Order X; Line 20000 of Order X Header of Order Y; Line 10000 of Order Y; Line 20000 of Order Y Line 30000 of Order Y My coworker suggested me to use a report to get that working, instead of a dataport. But he never tried that. If I am going to use a report, what will happen to all these delimiters (field separators), and also, how do I get the output as a text file? Thanks in advance. Sincerely, Sylvia Tsang Management Software Solutions, Inc. stsang@mgmtsoftware.com

What you are looking, one record - then all sub-records, cannot be done with a dataport. With a report you can, but you have to build your own export-to-file routines. That’s not too difficult, as you have all tools for this available. Take a look at the File functions of C/AL (file.Open, file.Write, etc.) John

You might also be able to do this as a report using standard report output, then printing to a Generic text printer and saving the output to a disk file. It would be crude, would have some embedded blanks but you could create the base structure of all the fields with the Report Designer wizard. I’ve not done exactly this, but have gotten similar things to work in the past. Dave Studebaker das@libertyforever.com Liberty Grove Software A Navision Services Partner

I had a similar problem some times ago. I took a Dataport with the DataItem PurchaseHeader. I placed Code in the OnAfterExportRecord - Trigger, like this: Line.SETRANGE(“Document Type”,Header.“Document Type”); Line.SETRANGE(“No.”,Header.“No.”); IF Line.FIND(’-’) THEN BEGIN CurrFile.WRITE(’ '); //This causes a new line REPEAT CurrFile.WRITE(FORMAT(Line)); UNTIL Line.NEXT = 0; END; It takes me some testing together with the DataItem-Properties but finaly it worked.

Micha, Your way to do it looks like a good idea. Nevertheless, I don’t know what I should do what the dataports’ fields. I have no problem with the Purchase Header dataport fields, but when comes to the Purchase Line, I deleted them, then, none of the lines showed. When I put them back, the fields appeared following the last field of the Purchase Header. So, I am still confused here. May I have some more information? Thank you. Sincerely, Sylvia Tsang Management Software Solutions, Inc. stsang@mgmtsoftware.com

Hi, You delete all the purchase lines? How do you know that you deleted them? Have you watched the variable during debugging or is it just a problem while designing the dataport? Hm, maybe that helps: No second DataItem. My suggestion is: Use only one DataItem: The PurchaseHeader. Take all Dataportfields you like from the FieldMenu. Line is a record-variable. Place the CAL-Code in the OnAfterExportRecord - Trigger of the Purchase Header. Micha

Micha, I followed your code, but it still didn’t start a new line when it tried to write the detail lines. Then, I asked my coworker, and he suggested me to enter an integer as follows: Attempt 1: CurrFile.write(’ '); Attempt 2: CurrFile.write(34); Attempt 3: CurrFile.write(38); They would give me a few space after the header was out, and also they would give me little symbols like a little square, the ampersend … etc. So, what should I do at this point? Thank you. Sincerely, Sylvia Tsang Management Software Solutions, Inc. stsang@mgmtsoftware.com

Hi Sylvia, because I saw your new posting, refering “report as a text file”, I suppose your problem could maybe belong to this posting, the dataport-problem. If this is the case, try one more thing in the dataport: Add: CurrFile.TEXTMODE(true); in the OnPreDataport Trigger. The empty Line or problems with the FieldSeparator you can solve using and testing the Dataport-properties. Micha

Micha, Thank you very, very much for your assistance. I finally got my dataport working the way I wanted it. I am glad I learned something new about dataport from this project. Anyway, here is the solution to my project, and it will be served as a future reference; Name of this dataport - Export Purchase Orders: OnBeforeExportRecord() Define all the fields for the Purchase Headers. OnAfterExportRecord() PurchLine.SETRANGE(“Document Type”,“Document Type”); PurchLine.SETRANGE(“Document No.”,“No.”); IF PurchLine.FIND(’-’) THEN BEGIN CurrFile.WRITE(’’); REPEAT BEGIN LineTransType := ‘D’; LineItem := PurchLine.“Line No.”; ItemNo := PurchLine.“No.”; ItemCrossRef.SETFILTER(“Item No.”,’% 1’,ItemNo); ItemCrossRef.SETFILTER(Type,’%1’,ItemCrossRef.Type::Vendor); ItemCrossRef.SETFILTER(“Type Reference Code”,’%1’,‘PRO389’); IF ItemCrossRef.FIND(’-’) THEN BEGIN ItemCodeProAct := ItemCrossRef.“Cross Reference No.”; END ELSE ItemCodeProAct := ‘’; ItemCodeMember := ‘’; Quantity := PurchLine.Quantity; Pack := PurchLine.“Unit of Measure”; // optional field Size := ‘’; // optional field AllowSubstitutes := ‘’; // optional field PackType := ‘’; // optional field OpenFutureUse1 := ‘’; // optional field CASE PurchLine.“Item Type” OF 0: BEGIN PriceMethod := ‘M’; ContractNumber := ‘Market’; END; 1: BEGIN PriceMethod := ‘C’; ContractNumber := ‘Contract’; END; 2: BEGIN PriceMethod := ‘P’; ContractNumber := ‘’; END; END; LineItemComments := ‘’; // optional field OpenFutureUse2 := ‘’; // optional field IF PurchLine.“Exported Record” THEN PurchLineText := ‘’ ELSE BEGIN PurchLine.“Exported Record” := TRUE; PurchLine.MODIFY; END; PurchLineText := LineTransType + ‘|’ + FORMAT(LineItem) + ‘|’ + ItemCodeProAct + ‘|’ + ItemCodeMember + ‘|’ + FORMAT(Quantity) + ‘|’ + Pack + ‘|’ + Size + ‘|’ + AllowSubstitutes + ‘|’ + PackType + ‘|’ + PriceMethod + ‘|’ + ContractNumber; CurrFile.WRITE(FORMAT(PurchLineText)); END; UNTIL PurchLine.NEXT =0; END; OnPreDataport() CurrFile.TEXTMODE(TRUE); Hint: On the Dataport Properties, go to the Import field, and make sure that it is equaled to ‘NO’. The rest of the stuff that you will have to define would be the dataport fields and also the global variables. That’s it. Sincerely, Sylvia Tsang Management Software Solutions, Inc. stsang@mgmtsoftware.com