Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Got C/AL? / Beginners Tip: Creating and...

Beginners Tip: Creating and Handling Headers in Dataports

Community Member Profile Picture Community Member

As “Dinosaur”-tech as it might seem these days with most blogs posting about RTC, dataports is still one of the easiest ways to import data into NAVision. Having to search my old databases for a quick way to handle headers in datafiles, i thought i would share this with you. Hopefully Google will answer you with this post next time you have to do it :) .

If you appreciate these beginners tips, let me know and i will dig into my archives before everyone leaves on the Dynamics Ark….

This small piece of code will handle writing headers when exporting, and also skipping the first datarow when importing.

OnPreDataItem()
IF NOT CurrDataport.IMPORT THEN BEGIN
  Tab := 9; // 9=TAB, if you use another field seperator change it here!
  // Write Header fields
  CurrFile.TEXTMODE(TRUE);
  CurrFile.WRITE(
  'Item No (20)' +
  FORMAT(Tab) +
  'Description (30)');
  CurrFile.TEXTMODE(FALSE);
END ELSE BEGIN
  // Skip header
  CurrFile.TEXTMODE(TRUE);
  CurrFile.READ(Dummy); // read line into text variable
  CurrFile.TEXTMODE(FALSE);
END;

This was originally posted here.

Comments

*This post is locked for comments