18 July 2019

X++ code to write data to Notepad or CSV file in D365FO or AX7

TextStreamIo                        streamIO;
FileName                            fileNameWithExt;
    FileName                            fileName;

 public void initFile()
    {
        #define.validationFileSuffix('-data-validation-errors.txt')
        InteropPermission perm = new InteropPermission(InteropKind::ClrInterop);
       
        perm.assert();
        streamIO = TextStreamIO::constructForWrite(#utf8format);
        streamIO.outRecordDelimiter(#delimiterCRLF);

        fileName += #validationFileSuffix;
    }

boolean validationFailed(FreeTxt _errorTxt)
    {
        boolean ret;

        if(!streamIO)
        {
            this.initFile();
        }
           
        streamIO.write(_errorTxt);

        return ret;
    }


 public void downloadFile()
    {
        if (streamIo != null)
        {
            File::SendFileToUser(streamIo.getStream(), fileName);
        }

        CodeAccessPermission::revertAssert();
    }

No comments:

Post a Comment

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension-...