web
You’re offline. This is a read only version of the page.
close
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...
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
    95,311 Super User 2025 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
    95,311 Super User 2025 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,177

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,467 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,435 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans