Thursday 2 July 2015

Import Text(Notepad) file data to AX Table

Import the records from Text file to Ax table in ax

static void ImportTextToAXTable(Args _args)
{
FilenameOpen filename;
dialogField dialogFilename;
Dialog dialog;
TextIO file;
NotepadTable notepadTable;
container con;
str conitem,conitem1,conitem2;
Filename filepath,fileType;
int i;
#File
dialog = new Dialog("Notepad Upload");
dialogFilename = dialog.addFieldValue(extendedTypeStr(FilenameOpen),filename,"File Name");
dialog.filenameLookupFilter([".txt", #AllFiles]);
dialog.filenameLookupTitle("Upload from Text File");
dialog.caption("Upload from text file");
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
file = new TextIO(filename, #IO_READ);
file.inRecordDelimiter('\n');
file.inFieldDelimiter(',');
[filepath, filename, fileType] = fileNameSplit(filename);
if(fileType==".txt")
{
ttsbegin;
while(file.status() == IO_STATUS::OK)
{
con = file.read();
conitem = conpeek(con,1);
if(conItem!="0")
{
notepadTable.initValue();
notepadTable.Name=conpeek(con,1);
notepadTable.Integer=conpeek(con,2);
notepadTable.insert();
}
}
ttscommit;
}
else
{
        info("File shoule be .txt format");
}

USER CAN GIVE INPUT MANUALLY INTO LOOKUP FIELD IN AX

TASK:

In my Table I have serial number field in that I want to enter manually serial numbers not taken from lookup but at the same time i don't want to save in InventSerial Table but i need to save my input into current table.

Simple Steps:
In Table level methods,

public boolean validateField(fieldId _fieldIdToCheck)
{
    boolean ret;
    ;
    if (_fieldIdToCheck == fieldnum(CurrentTable,InventSerialId))
        ret = true;
    else
        ret = super(_fieldIdToCheck);
    return ret;
}