How to do it...

  1. In Visual Studio Code, open the televisionShow folder that you extracted from ch9-start.zip and that we've been working on in the previous recipes of this chapter.
  2. Right-click on the codeunit folder and create a new file named App Install.al.
  3. Create a new codeunit object:
codeunit 50111 "App Install"
{

}
  1. Add the Subtype = Install attribute to the codeunit object:
codeunit 50111 "App Install"
{
Subtype = Install;

}

This will cause the codeunit object to be executed when the application is installed for the first time.

  1. Add the following trigger and logic:
trigger OnInstallAppPerCompany()
begin
InstallTelevisionSetup();
EnableApplicationArea();
InstallSampleTelevisionShows();
end;

Now, when the application is installed, it will perform the following:

  • Create the Television Show Setup record, which is needed before any television show data can be created.
  • Automatically enable the Television Show application area that we previously added (Chapter 2, Customizing What's Already There, in the Adding application areas recipe).
  • Install the sample Television Show entries that we previously only allowed the user to do manually (Chapter 3, Let's Go Beyond, in the Assisted setup wizards recipe).
Remember, as developers, we need to be concerned about the user experience at all times. If the application can do some setups automatically for the user, then it will make for a much nicer experience.
  1. Add the following code to insert the TelevisionSetup record:
local procedure InstallTelevisionSetup()
var
TelevisionSetup: Record "Television Show Setup";
begin
if not TelevisionSetup.IsEmpty then
exit;
TelevisionSetup.Init();
TelevisionSetup.Insert(true);
end;
  1. Now, add the following function to enable the application area:
local procedure EnableApplicationArea()
var
EnableTvApplicationArea: Codeunit "Enable TV Application Area";
begin
if not EnableTvApplicationArea.IsTelevisionShowsEnabled() then
EnableTvApplicationArea.EnableTelevisionShows();
end;
  1. Add the following function to install the sample Television Show records:
local procedure InstallSampleTelevisionShows()
var
LoadTvShows: Codeunit "Load Television Shows";
begin
LoadTvShows.LoadTelevisionShows(true, true, true);
end;

  1. Now, press F5 to build and install your application. Log in to your sandbox and notice the following:
    • The Television Show List is populated with the sample data.
    • On the Application Area page, the Television Shows area is enabled.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.29.145