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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

A DotNet variable has not been instantiated.

(0) ShareShare
ReportReport
Posted on by
Hi couldl someone tell me how I'm able to instantiated a DotNet Variable of a control add-in?
codeunit 50545 MergeDocs
{
    Access = Public;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnAfterFinalizePostingOnBeforeCommit', '', false, false)]
    local procedure MyProcedure(var SalesInvoiceHeader: Record "Sales Invoice Header")
    var
        Recref2: RecordRef;
        TestText: Text[2500];
        MergePDF: Codeunit MergePDF1;
    begin
        SalesInvoiceHeader.FindFirst();
        SalesInvoiceHeader.SetRange("No.", SalesInvoiceHeader."No.");
        Recref2.GetTable(SalesInvoiceHeader);
        MergePDF.AddReportToMerge(50500, Recref2); //Ximiq Invoice
        MergePDF.AddReportToMerge(11510, Recref2); //QR-Invoice
        Base64string := MergePDF.GetJArray();
        Message(DocumentAdded, SalesInvoiceHeader."No.");
        Control.MergePDF(Format(Base64string));
    end;
    var
        DocumentAdded: Label 'Document %1 added';
        Control: ControlAddIn PDF;
        Base64string: JsonArray;
thank you so much 
I have the same question (0)
  • Verified answer
    YUN ZHU Profile Picture
    102,883 Super User 2026 Season 2 on at

    Hi, .NET Interoperability is only available on-premise. If you want to use this functionality, you must set the "target": "OnPrem" in the app.json file.

    More detials: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-get-started-call-dotnet-from-al

    And if you want to merge PDF, here is an awesome Javascript solution. This can be used in SaaS.

    Merge PDF in Business Central (linkedin.com)

    GitHub - gonzaloriosley/Merge-PDF-Business-Central

    Hope this will help.

    Thanks

    ZHU

  • Sleina Profile Picture
    on at

    Thank you very much!

  • Sleina Profile Picture
    on at

    yzhums is it possible to call the scripts/controlAddin from an eventsubscription?

    I would need to merge documents right after the following event: OnAfterFinalizePostingOnBeforeCommit

    I can't seem to make it work

    Thank you so much in advance for your help!

  • Verified answer
    YUN ZHU Profile Picture
    102,883 Super User 2026 Season 2 on at

    Hi, yes, as I understand, this usercontrol cannot be executed without being added to the page.

    So, unfortunately, you need to change the solution.

    I'm sorry I haven't tried the below solution, but I think you can give it a try.

    Using Azure Function to combine PDF.

    https://powergi.net/2021/04/12/505-2/

    https://www.sharepointeurope.com/merge-pdf-files-in-sharepoint-using-an-azure-function/

    Using Azure Functions with Dynamics 365 Business Central

    https://docs.microsoft.com/en-us/learn/modules/use-azure-functions/

    https://ksdconsultancy.blog/2021/11/28/integrating-azure-function-with-business-central/

    A ftp sample: https://demiliani.com/2021/12/07/dynamics-365-business-central-handling-files-via-ftp-on-saas/

    Hope this also helps.

    Thanks.

    ZHU

  • Sleina Profile Picture
    on at

    Thank you so much this helps a lot! :)

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 601 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 338 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 329 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans