Showing posts with label import. Show all posts
Showing posts with label import. Show all posts

Thursday, June 25, 2009

Import data in Navision using dataport while skipping the header line.


I faced a small challenge recently to import a .csv file using a dataport, while skipping the header line, which had the coloumn names. Here are the steps I followed.


  • Create a new dataport with just one Integer dataitem.
  • Create global text variables for every coloumn you want to import.
  • Enter the variables as dataport fields for the Integer dataitem.
  • Now, create a global Recordcount variable of "Integer" datatype and initialize it to 0 in the OnPreDataItem.trigger of Integer dataitem.
  • Create a global "Record" variable for the table where you want to insert the records e.g MyEmpTable.
  • Increment the variable in the OnAfterImportRecord trigger. e.g. Recordcount +=1;
  • Check if the values of Recordcount is greater than 1 and in the if loop write the code to input the data into the desired table.

Integer - OnAfterImportRecord()

MyEmpTable.INIT;
IF RecCount > 1 THEN BEGIN
   WITH MyEmpTable DO BEGIN
     "Employee No." := _EmpNo;  
     EVALUATE(Date,_Date);
     EVALUATE("Time In",_TimeIn);
     EVALUATE("Time Out",_TimeOut);
     EVALUATE("Attendance Type",_AttenType);
     INSERT(TRUE);
   END;
END;
RecCount += 1;

This way all records after the header line will be inserted into the desired table.