Exercise - Create the Customer Rewards Wizard page object
Scenario
The following code adds a Customer Rewards Wizard page that enables the user to accept the terms for using and activating the extension.
The page consists of the following steps:
Welcome - The welcome step has a check box for the Terms of Use that must be enabled.
Activation - The activation step has a text box where the activation code must be entered for validation. A valid activation code for this sample extension is any 14-character alphanumeric code.
Finish - The last step on the page.
You can use a NavigatePage type to create a wizard that leads the user through a sequence of steps for completing a task.
Create the Customer Rewards Wizard page object
To create the Customer Rewards Wizard page object, follow these steps:
Create a new .al file.
To create a new page in your extension, first create a new file. Select the New File button in the side bar of Visual Studio Code.
Make sure that the filename ends with .al. In this example, you might want to use the name CustomerRewardsWizard.Page.al.
Add the code to the page. You can copy the following code and paste it in the CustomerRewardsWizard.Page.al file.
page 50100 "Customer Rewards Wizard"
{
// Specifies that this page will be a navigate page.
PageType = NavigatePage;
Caption = 'Customer Rewards assisted setup guide';
layout
{
area(content)
{
group(MediaStandard)
{
Caption = '';
Editable = false;
Visible = TopBannerVisible;
field("Media Reference"; MediaResourcesStandard."Media Reference")
{
ApplicationArea = All;
Editable = false;
ShowCaption = false;
}
}
group(FirstPage)
{
Caption = '';
Visible = FirstPageVisible;
group("Welcome")
{
Caption = 'Welcome';
Visible = FirstPageVisible;
group(Introduction)
{
Caption = '';
InstructionalText = 'This Customer Rewards extension is a sample extension. It adds rewards tiers support for Customers.';
Visible = FirstPageVisible;
field(Spacer1; '')
{
ApplicationArea = All;
ShowCaption = false;
Editable = false;
MultiLine = true;
}
}
group("Terms")
{
Caption = 'Terms of Use';
Visible = FirstPageVisible;
group(Terms1)
{
Caption = '';
InstructionalText = 'By enabling the Customer Rewards extension...';
Visible = FirstPageVisible;
}
}
group(Terms2)
{
Caption = '';
field(EnableFeature; EnableCustomerRewards)
{
ApplicationArea = All;
MultiLine = true;
Editable = true;
Caption = 'I understand and accept these terms.';
ToolTip = 'Click to confirm: I understand and accept these terms.';
trigger OnValidate();
begin
ShowFirstPage();
end;
}
}
}
}
group(SecondPage)
{
Caption = '';
Visible = SecondPageVisible;
group("Activation")
{
Caption = 'Activation';
Visible = SecondPageVisible;
field(Spacer2; '')
{
ApplicationArea = All;
ShowCaption = false;
Editable = false;
MultiLine = true;
}
group(ActivationMessage)
{
Caption = '';
InstructionalText = 'Enter your 14 digit activation code to continue';
Visible = SecondPageVisible;
field(Activationcode; ActivationCode)
{
ApplicationArea = All;
ShowCaption = false;
Editable = true;
}
}
}
}
group(FinalPage)
{
Caption = '';
Visible = FinalPageVisible;
group("ActivationDone")
{
Caption = 'You''re done!';
Visible = FinalPageVisible;
group(DoneMessage)
{
Caption = '';
InstructionalText = 'Click Finish to set up your rewards level and start using Customer Rewards.';
Visible = FinalPageVisible;
}
}
}
}
}
actions
{
area(Processing)
{
action(ActionBack)
{
ApplicationArea = All;
Caption = 'Back';
Enabled = BackEnabled;
Visible = BackEnabled;
Image = PreviousRecord;
InFooterBar = true;
trigger OnAction();
begin
NextStep(true);
end;
}
action(ActionNext)
{
ApplicationArea = All;
Caption = 'Next';
Enabled = NextEnabled;
Visible = NextEnabled;
Image = NextRecord;
InFooterBar = true;
trigger OnAction();
begin
NextStep(false);
end;
}
action(ActionActivate)
{
ApplicationArea = All;
Caption = 'Activate';
Enabled = ActivateEnabled;
Visible = ActivateEnabled;
Image = NextRecord;
InFooterBar = true;
trigger OnAction();
var
CustomerRewardsExtMgt: Codeunit "Customer Rewards Ext Mgt";
begin
if ActivationCode = '' then
Error('Activation code cannot be blank.');
if Text.StrLen(ActivationCode) <> 14 then
Error('Activation code must have 14 digits.');
if CustomerRewardsExtMgt.ActivateCustomerRewards(ActivationCode) then
NextStep(false)
else
Error('Activation failed. Please check the activation code you entered.');
end;
}
action(ActionFinish)
{
ApplicationArea = All;
Caption = 'Finish';
Enabled = FinalPageVisible;
Image = Approve;
InFooterBar = true;
trigger OnAction();
begin
FinishAndEnableCustomerRewards();
end;
}
}
}
trigger OnInit();
begin
LoadTopBanners();
end;
trigger OnOpenPage();
begin
Step := Step::First;
EnableControls();
end;
local procedure EnableControls();
begin
ResetControls();
case Step of
Step::First:
ShowFirstPage();
Step::Second:
ShowSecondPage();
Step::Finish:
ShowFinalPage();
end;
end;
local procedure NextStep(Backwards: Boolean);
begin
if Backwards then
Step := Step - 1
ELSE
Step := Step + 1;
EnableControls();
end;
local procedure FinishAndEnableCustomerRewards();
var
CustomerRewardsExtMgt: Codeunit "Customer Rewards Ext Mgt";
GuidedExperience: Codeunit "Guided Experience";
Info: ModuleInfo;
begin
NavApp.GetCurrentModuleInfo(Info);
GuidedExperience.CompleteAssistedSetup(ObjectType::Page,PAGE::"Customer Rewards Wizard");
CurrPage.Close();
CustomerRewardsExtMgt.OpenRewardsLevelPage();
end;
local procedure ShowFirstPage();
begin
FirstPageVisible := true;
SecondPageVisible := false;
FinishEnabled := false;
BackEnabled := false;
ActivateEnabled := false;
NextEnabled := EnableCustomerRewards;
end;
local procedure ShowSecondPage();
begin
FirstPageVisible := false;
SecondPageVisible := true;
FinishEnabled := false;
BackEnabled := true;
NextEnabled := false;
ActivateEnabled := true;
end;
local procedure ShowFinalPage();
begin
FinalPageVisible := true;
BackEnabled := true;
NextEnabled := false;
ActivateEnabled := false;
end;
local procedure ResetControls();
begin
FinishEnabled := true;
BackEnabled := true;
NextEnabled := true;
ActivateEnabled := true;
FirstPageVisible := false;
SecondPageVisible := false;
FinalPageVisible := false;
end;
local procedure LoadTopBanners();
begin
if MediaRepositoryStandard.GET('AssistedSetup-NoText-400px.png', FORMAT(CURRENTCLIENTTYPE))
then
if MediaResourcesStandard.GET(MediaRepositoryStandard."Media Resources Ref")
then
TopBannerVisible := MediaResourcesStandard."Media Reference".HASVALUE;
end;
var
MediaRepositoryStandard: Record "Media Repository";
MediaResourcesStandard: Record "Media Resources";
Step: Option First,Second,Finish;
ActivationCode: Text;
TopBannerVisible: Boolean;
FirstPageVisible: Boolean;
SecondPageVisible: Boolean;
FinalPageVisible: Boolean;
FinishEnabled: Boolean;
BackEnabled: Boolean;
NextEnabled: Boolean;
ActivateEnabled: Boolean;
EnableCustomerRewards: Boolean;
}