Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Incoming documents from email or Power Automate

(1) ShareShare
ReportReport
Posted on by 370

Hello,
we use BC v16 in SaaS.

We need to speed up the import of Incoming documents, instead of opening BC web interface and manual PDF file import/upload.

Is it possible to somehow other way to import incoming documents? I do not see option through Power Automate (aka Flow) to create Incoming document with binary (PDF) attachment.

Any other way for faster processing, maybe we can forward attachment via email somehow/somewhere?

Thank you

  • AntonHa Profile Picture
    5 on at
    RE: Incoming documents from email or Power Automate

    I can publish this application, but what do i need to do after that?
    In Flow (Power Automate), what do i need to do to send my attachment to business central?

  • Suggested answer
    CFerland Profile Picture
    19 on at
    RE: Incoming documents from email or Power Automate

    Hi, this is what I got from our engineer

    codeunit 50104 "IncomingDocumentsExtension"
    {
    var
    incomingDocument: Record "Incoming Document";
    incomingDocumentAtt: Record "Incoming Document Attachment";

    trigger OnRun()
    begin

    end;

    //MY METHOD

    procedure ImportDocumentAsJSON(document: Text) ReturnValue: Text
    var
    token: JsonToken;
    tokenAtt: JsonToken;
    documentParsed: JsonObject;
    attObj: JsonObject;
    attArray: JsonArray;
    att: JsonToken;
    docDescription: text;
    docStatusField: text;
    TempBlob: Record TempBlob temporary;
    //For Debug
    resp: text;
    respB: Boolean;
    begin
    // Process JSON

    if not documentParsed.ReadFrom(document) then
    Error('Invalid response, expected an JSON OBJECT as root object');


    //Inserting Document into table 130
    incomingDocument.Init();
    incomingDocument.Description := GetJsonToken(documentParsed, 'Description').AsValue.AsText;
    incomingDocument.CreateIncomingDocument(incomingDocument.Description, '');


    //Inserting attachment and linking to previous document inserted
    incomingDocumentAtt.Init();
    TempBlob.FromBase64String(GetJsonToken(documentParsed, 'MainAttachment').AsValue.AsText);
    incomingDocumentAtt.Content := TempBlob.Blob;
    incomingDocumentAtt."Incoming Document Entry No." := incomingDocument."Entry No.";
    incomingDocumentAtt.Type := incomingDocumentAtt.Type::Other;
    incomingDocumentAtt."Line No." := 10000;
    incomingDocumentAtt."Main Attachment" := True;
    documentParsed.Get('SupportingAttachments', tokenAtt);
    foreach att in tokenAtt.AsArray() do begin
    if att.IsObject() then begin
    attObj := att.AsObject();
    incomingDocumentAtt.Name := GetJsonToken(attObj, 'Name').AsValue.AsText;
    incomingDocumentAtt."File Extension" := GetJsonToken(attObj, 'File_Extension').AsValue.AsText;
    end;
    end;
    respB := incomingDocumentAtt.Insert();


    ReturnValue := StrSubstNo('Result: Was the item Inserted? %1. Document ID: %2', respB, incomingDocument."Entry No.");
    end;


    //BASIC CONVERTIONS FOR JSON
    procedure GetJsonToken(JsonObject: JsonObject; TokenKey: text) JsonToken: JsonToken;
    begin
    if not JsonObject.Get(TokenKey, JsonToken) then
    Error('Could not find a token with key %1', TokenKey);
    end;

    procedure SelectJsonToken(JsonObject: JsonObject; Path: text) JsonToken: JsonToken;
    begin
    if not JsonObject.SelectToken(Path, JsonToken) then
    Error('Could not find a token with path %1', Path);
    end;
    }

  • CIT_pakr Profile Picture
    30 on at
    RE: Incoming documents from email or Power Automate

    hi, do you have a example for that ?

  • Suggested answer
    CFerland Profile Picture
    19 on at
    RE: Incoming documents from email or Power Automate

    Hi, we managed to get this thing working.

    This is the briefing I got from our architect who figured it out.

    Solution:

    Since SOAP can't receive any stream files, we figure out we needed to create an endpoint (CodeUnit) to receive a new object (incomingDocuments + file as base64) as JSON. Once into BC, using AL, everything is easier. To save Incoming Documents (Table 130) we just create using a Description value (which is the same to name it) and get the value of Id after created. Next we create an Incoming Document Attachment (Table 133) using the previous Id of document to attached. The trick here was, with the base64 value, we created a Blob with it (TempBlob.FromBase64String()) and added as Content. To save into the table, we used ".Insert()".

  • Hrvoje Kusulja Profile Picture
    370 on at
    RE: Incoming documents from email or Power Automate

    Sorry, can you explain in more detail. How to create Power Automate (Flow) to (example on triger email , extract attachment binary content) and to upload to BC production environment inside "Incoming document" with attachment content, using native BC connector? I did not manage to get it working :/

  • Suggested answer
    JAngle Profile Picture
    89 on at
    RE: Incoming documents from email or Power Automate

    Power automate (flow) has an attachment endpoint which is in fact the incoming document feature of BC. As part of this flow you have to post a value which gives us an ID and then you use that ID to patch a binary file.

    Other processing options would most likely be ISV add ins like Continia document capture as an example

  • CFerland Profile Picture
    19 on at
    RE: Incoming documents from email or Power Automate

    Hi, did you find a solution to this problem ? Or anybody else have the same issue ?

    We are also trying to import Incoming Documents using PowerAutomate.... We did expose a web service in BC that allows us to create and incoming document table entry but we can't get the actuel attachment with it since it appears to be another table and the upload thru BC is done using a main filestream upload that doesn't seem to be available.  

    Maybe someone has experience with BD "Import" feature that triggers the proprietary filestream upload ?

    Thanks !

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
YUN ZHU Profile Picture

YUN ZHU 628 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 495

#3
Sagar Dangar, MCP Profile Picture

Sagar Dangar, MCP 395

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans