Options

Import data using RecordRef and FieldRef - How I Import data to correct tables and fields?

RainerRainer Member Posts: 103
I created a Codeunit which by RecordRef and FieldRef export data to file or Table including all data from each field; this works great.

Based on the info I have I now want to import data to correct tables and fields but seams to give me some problems. Anybody have an idea for how to? I really appreciate if anybody can help me.

Here is code for export data which works fine.

Window.OPEN('Export Tabledata from #1##################\'+
'Fielddata #2##################');

Window.UPDATE(1,'');
Window.UPDATE(2,'');

TableObject.SETRANGE(Type,TableObject.Type::TableData);
TableObject.SETRANGE("Company Name",COMPANYNAME);
IF TableObject.FINDFIRST THEN
REPEAT
ExportTableDataRef.OPEN(TableObject.ID);

Window.UPDATE(1,TableObject.Name);

IF ExportTableDataRef.FINDFIRST THEN BEGIN
ExportRecordTrigger := 0;
REPEAT
ExportRecordTrigger := ExportRecordTrigger + 1;
FOR i := 1 TO ExportTableDataRef.FIELDCOUNT DO BEGIN
ExportFieldData := ExportTableDataRef.FIELDINDEX(i);
ExportFieldNo := ExportFieldData.NUMBER;
ExportFieldName := ExportFieldData.NAME;

Window.UPDATE(2,ExportFieldName);

CompanyData.RESET;
IF NOT CompanyData.FINDLAST THEN
NextLineNo := 1
ELSE
NextLineNo := CompanyData."Line No" + 1;

CompanyData.INIT;
CompanyData."Line No" := NextLineNo;
CompanyData."Record Trigger" := ExportRecordTrigger; // Counter of records in the current table
CompanyData."Table Id" := ExportTableDataRef.NUMBER; // Table Id
CompanyData."Table Name" := ExportTableDataRef.NAME; // Table Name
CompanyData."Field No" := ExportFieldNo; // Field No
CompanyData."Field Name" := ExportFieldName; // Field Name
CompanyData."Field Data" := FORMAT(ExportFieldData); // Current Field Data (I might export Field Type as well)
CompanyData.INSERT;
END;
UNTIL (ExportTableDataRef.NEXT = 0);
END;
ExportTableDataRef.CLOSE;
UNTIL (TableObject.NEXT = 0);

Kind Regards

E-mail: info@rainerbay.dk
Skype: rainerbaydk

Answers

  • Options
    NavNabNavNab Member Posts: 181
    edited 2018-04-25
    You can check CU 8611. There is a lot of functions that could inspire you ;)
  • Options
    RainerRainer Member Posts: 103
    Hi NavNab, I will take a look at that, thanks for your comment :-)
    Kind Regards

    E-mail: info@rainerbay.dk
    Skype: rainerbaydk
Sign In or Register to comment.