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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum

Install codeunit not working

(0) ShareShare
ReportReport
Posted on by 525

Hi guys
I have created a codeunit with subtype=Install. Its purpose is to create a couple of webservices and initialize Stripe data(for app monetization) on installation. But when I publish the app, neither does it create the web services nor does it initialize any data.
I have tried both (OnInstallAppPerCompany and OnInstallAppPerDatabase). Also tried to uninstall and unpublish app before publishing again but nothing seems to work. Is it something in the launch.json or app.json that's causing the issue? 
Codeunit is given below. Thank you in advance :) 

codeunit 500750 "App Installation"
{
    Subtype = Install;
    trigger OnInstallAppPerCompany()
    begin
        InitStripeData();
    end;

    trigger OnInstallAppPerDatabase();
    var
        myAppInfo: ModuleInfo;
    begin

        NavApp.GetCurrentModuleInfo(myAppInfo); // Get info about the currently executing module
        if myAppInfo.DataVersion = Version.Create(0, 0, 0, 0) then // A 'DataVersion' of 0.0.0.0 indicates a 'fresh/new' install

            PublishWebServices()
        else
            PublishWebServices();
    end;

    local procedure PublishWebServices()
    var
        WebServiceRec: Record "Web Service Aggregate";
    begin
        if not WebServiceRec.Get(WebServiceRec."Object Type"::Codeunit, 'DataExport') then begin
            with WebServiceRec do begin
                Init();
                "Object Type" := "Object Type"::Codeunit;
                "Object ID" := 70112322;
                "Service Name" := 'DataExportCU';
                Published := true;
            end;
            WebServiceRec.Insert(true);
        end;

        if not WebServiceRec.Get(WebServiceRec."Object Type"::Codeunit, 'ImportDataCU') then begin
            with WebServiceRec do begin
                Init();
                "Object Type" := "Object Type"::Codeunit;
                "Object ID" := 70112323;
                "Service Name" := 'ImportData';
                Published := true;
            end;
            WebServiceRec.Insert(true);
        end;
    end;

    local procedure InitStripeData()
    var
        StripeSetup: Record "StripeSetup";
    begin
        StripeSetup.RefreshData();
    end;
}


Categories:
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,172 Most Valuable Professional on at

    Best way to create a web service from Install codeunit is explained here:

    demiliani.com/.../dynamics-365-business-central-publishing-a-web-service-from-extensions

  • KonstantinLevchenko Profile Picture
    on at

    Hi Mohsin,

    I'm trying to find a demo code from Microsoft regarding Stripe Integration. It was available for download before, but now all links are broken :( . I'm wondering if you still has this demo code and can share it ... I'm looking C/AL version.

  • Mohsin Abbas Profile Picture
    525 on at

    Hi Konstantin

    Sorry for late reply. I have the AL version of it. Please let me know if that would work.

    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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans