Skip to main content

Notifications

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();
    }

  • tristansenk99 Profile Picture
    tristansenk99 89 on at
    RE: Attach StreamIO file as a new Attachment

    This did the trick! Thanks Martin

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,836 Most Valuable Professional on at
    RE: Attach StreamIO file as a new Attachment

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

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Attach StreamIO file as a new Attachment

    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.

  • tristansenk99 Profile Picture
    tristansenk99 89 on at
    RE: Attach StreamIO file as a new Attachment

    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');
            }

  • tristansenk99 Profile Picture
    tristansenk99 89 on at
    RE: Attach StreamIO file as a new Attachment

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

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Attach StreamIO file as a new Attachment

    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
    tristansenk99 89 on at
    RE: Attach StreamIO file as a new Attachment

    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.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Attach StreamIO file as a new Attachment

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans