Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

A DotNet variable has not been instantiated.

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 
Categories:
  • Sleina Profile Picture
    Sleina on at
    RE: A DotNet variable has not been instantiated.

    Thank you so much this helps a lot! :)

  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 70,116 Super User 2024 Season 2 on at
    RE: A DotNet variable has not been instantiated.

    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
    Sleina on at
    RE: A DotNet variable has not been instantiated.

    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!

  • Sleina Profile Picture
    Sleina on at
    RE: A DotNet variable has not been instantiated.

    Thank you very much!

  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 70,116 Super User 2024 Season 2 on at
    RE: A DotNet variable has not been instantiated.

    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

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,647 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans