OnInstallPerCompany not working
Hello,
when I deploy my package to Business Central (Cloud) the OnInstallPerCompany is not getting triggered. Any ideas?
codeunit 50100 InstallCodeunit { Subtype = Install;
trigger OnInstallAppPerCompany() var ReportSelection: Record "Report Selections"; begin ReportSelection.RESET; ReportSelection.SetRange(Usage,ReportSelection.USAGE::"S.Invoice"); If ReportSelection.FINDFIRST THEN repeat ReportSelection.DELETE(TRUE); UNTIL ReportSelection.NEXT=0; ReportSelection.SetRange(Usage,ReportSelection.USAGE::"S.Cr.Memo"); If ReportSelection.FINDFIRST THEN repeat ReportSelection.DELETE(TRUE); UNTIL ReportSelection.NEXT=0;
ReportSelection.Init();
ReportSelection.VALIDATE(Usage,ReportSelection.Usage::"S.Invoice");
ReportSelection.VALIDATE(Sequence,'1');
ReportSelection.VALIDATE("Report ID",50101);
ReportSelection.INSERT;
ReportSelection.Init();
ReportSelection.VALIDATE(Usage,ReportSelection.Usage::"S.Cr.Memo");
ReportSelection.VALIDATE(Sequence,'1');
ReportSelection.VALIDATE("Report ID",50102);
ReportSelection.INSERT;
end; }
best regards, Thomas Barbut
Are you saying that it doesn't execute 'any more' or that it never did?
The OnInstallAppPerCompany trigger will only execute on a 'new' installation of the extension, or during a reinstallation (I.e. this first time you install, or if you uninstall and reinstall the same version). See: Writing Extension Install Code
The only other case is when you have increased the version number of the extension in the app.json, in which case you are performing an upgrade. In this case, if you want to execute code, you must put it in an upgrade codeunit and utilize the OnUpgradePerCompany or OnUpgradePerDatabase triggers. See: Upgrading Extensions V2
Hello,
It is indeed an upgrade. Thanks for the help. This solved my issue!
best regards, Thomas Barbut
Glad to help.
I'm getting the same issue although I haven't changed the version of app. Tried uninstalling and un-publishing the app before publishing again but still it didn't work. Have tried OnInstallPerCompany and onInstallPerDatabase both. what else could be wrong?
`codeunit 70112320 "App Installation" { Subtype = Install;
trigger OnInstallAppPerDatabase();
var
myAppInfo: ModuleInfo;
begin
InitStripeData();
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" := 'DataExport';
Published := true;
end;
WebServiceRec.Insert(true);
end;
if not WebServiceRec.Get(WebServiceRec."Object Type"::Codeunit, 'ImportData') 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;
}`
What about this code doesn't seem to be working/firing? If you have done an uninstall/reinstall then this code should most definitely be firing.
Are you just not seeing entries in the web services table after performing these inserts? Or are you expecting different behavior? Note that since the services are being inserted here in code, they will not be removed when the extension is uninstalled
Web services should actually be included in an xml file inside of the extension, see Exporting data for Extensions
The webservices aren't being created in the first place. Same goes for the Stripe data. I have tried to publish/install app with a different name/id after removing the earlier version but still it doesn't work. Regarding the use of Xml files, I will use xml's for webservices but at this point, at least the InitStripeData() function should work because it doesnt have anything to do with the services.
I'm currently getting a similar error message, while executing a get webservice call, during the installation routine. I'm doing this to get my stripe products The error message says that "Publishing app fails due to "callback" functions". When I comment out the installation code everything works fine.
I'm definitely not able to reproduce this issue as of yet. Could you try a sanity check test and just throw an error inside of the code? Something like the following codeunits would assert the path of execution. You should receive an error indicating where/what was code was fired.
codeunit 70112320 UpgCodeunit
{
Subtype = Upgrade;
trigger OnUpgradePerCompany()
begin
Error('ERRROR In UpgPerComp');
end;
trigger OnUpgradePerDatabase()
begin
Error('ERRROR In UpgPerData');
end;
}
codeunit 70112321 InstallCodeunit
{
Subtype = Install;
trigger OnInstallAppPerCompany()
begin
Error('ERRROR In InstPerComp');
end;
trigger OnInstallAppPerDatabase()
begin
Error('ERRROR In InstPerData');
end;
}