web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Attach StreamIO file as a new Attachment

(1) ShareShare
ReportReport
Posted on by 89

I have a requirement to attach ACH payment files (vendor payment journal > Generate Payments) to a new attachment in a custom table. My code below works in creating the attachment, but when I go to the attachment and press "Open" the file is blank. The actual file that is delivered to the user's screen (through standard code) is not blank so the attachment should match this one exactly. The file name and everything else comes across, but the content is just blank. Additionally, in the DocumentManagement::AttachFile method, parameter 5 'filecontent' is not null when I debug it. Am I missing an intermediary step like uploading the file to URL/Temp storage or blob? If so, how can that be done? Or do you see anything that needs to be tweaked in my code? Parameter 7 is optional.

[ExtensionOf(classStr(CustVendOutPaym))]
final class-

        DocuRef docuRef;
       
        if(file)
        {
            DocuRef = DocumentManagement::attachFile(tableName2Id('CE_BankIntegrationStorageTable'), bankIntegrationStorageTable.RecId, bankIntegrationStorageTable.DataAreaId, DocuType::typeFile(), fileContent, filename,'TXT',filename, 'ACH file');
        }
       -
        //make file null here
        next closefile();
    }

I have the same question (0)
  • GirishS Profile Picture
    27,833 Moderator on at

    Hi tristansenk99,

    What is the file name and file type you are attaching.

    May be the file type you are uploading is not supported in document management.

    Thanks,

    Girish S.

  • tristansenk99 Profile Picture
    89 on at

    Hi Girish. thanks for your reply.

    My file name is a string, in this case it is 'ACH_02212023 03409'. The file type is a txt file.

  • Suggested answer
    GirishS Profile Picture
    27,833 Moderator on at

    You need to either pass the file type in the file name or pass the file type in the arguments.

    Just try the below code and check.

    DocuRef = DocumentManagement::attachFile(tableName2Id('CE_BankIntegrationStorageTable'), bankIntegrationStorageTable.RecId,
                bankIntegrationStorageTable.DataAreaId, 'File', fileContent, filename,'TXT',filename, 'ACH file');

    Thanks,

    Girish S.

  • tristansenk99 Profile Picture
    89 on at

    Here is my updated code. Still experiencing blank file. Txt file itself generates but its just blank.

  • tristansenk99 Profile Picture
    89 on at

    Here is my update code. The txt file export is getting generated (I can download it), but it is just blank still.

     if(file)
            {
                DocuRef = DocumentManagement::attachFile(tableName2Id('CE_BankIntegrationStorageTable'), bankIntegrationStorageTable.RecId, bankIntegrationStorageTable.DataAreaId, DocuType::typeFile(), fileContent, filename,'TXT',filename, 'ACH file');
            }

  • GirishS Profile Picture
    27,833 Moderator on at

    What is the file type when you are downloading it. Is it downloaded as text file?

    Also try to debug inside the attachFile method of Document management. On the File information tab check whether file type is populated on document management form.

    Also try the code like below.

    http://www.theaxapta.com/2013/04/x-code-for-document-attachment.html

    Thanks,

    Girish S.

  • Verified answer
    Martin Dráb Profile Picture
    238,846 Most Valuable Professional on at

    Aren't you already at the end of the stream? Maybe you just need to reset the position: fileContent.Position = 0.

  • tristansenk99 Profile Picture
    89 on at

    This did the trick! Thanks Martin

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 470

#3
Adis Profile Picture

Adis 270 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans