Write data to .txt file (X++)

Hi, in this write i will explain how to write specific data from a table to a ."txt" file with X++ code.

In the job example below, you will see that we specify the file and folder location and then take permission to "write". Then we loop through "InventTable" data without any filters and write down the "ItemId" column.


static void writeInventRecIdToTxtFile(Args _args)
{
    InventTable         inventTable;
    container           reclist;
    TextIo              file;
    int                 i = 0;
    Filename            filename = @"C:\exampleFolder\example.txt"; //Specify the path for folder and .txt file before runnig this job.
    FileIOPermission    permission;
    #File
    ;
    
    try
    {
    permission = new FileIOPermission(Filename, "w");   //Give permission to write in file.
    permission.assert();

    file = new TextIo(filename, "w");   //New file with the write mode.
            
    if(!file)
        throw Exception::Error;

            
        while select inventTable
        {
            i++;
            reclist = conNull();
            reclist = [inventTable.ItemId];
            
            file.write(strFmt("%1.%2%3",i,"Numbered ItemId ==> ",con2Str(reclist,"")));
        }
    }
    catch(Exception::Error) 
    {
        error("File not found!");
    }
        CodeAccessPermission::revertAssert();
        info("Write process completed!");
    }

Comments

Popular posts from this blog

How to find Company Logo (X++)

How to find MainAccount with LedgerDimension (X++)

How to do barcode in SSRS (X++)