Ejercicio: Crear el objeto de página del Asistente de recompensas para clientes
Escenario
El código siguiente agrega una página Asistente de recompensas para clientes, que permite al usuario aceptar los términos para usar y activar la extensión.
La página consta de los siguientes pasos:
Bienvenida: el paso de bienvenida tiene una casilla de verificación para los Términos de uso que debe habilitarse.
Activación: el paso de activación tiene un cuadro de texto donde se debe introducir el código de activación para la validación. Un código de activación válido para esta extensión de ejemplo es cualquier código alfanumérico de 14 caracteres.
Finalización: el último paso en la página.
Puede usar el tipo NavigatePage para crear un asistente que guíe al usuario a través de una secuencia de pasos para completar una tarea.
Crear el objeto de página del Asistente de recompensas para clientes
Para crear el objeto de página Asistente de recompensas para clientes, siga estos pasos:
Cree un nuevo archivo .al.
Para crear una nueva página en su extensión, primero cree un nuevo archivo. Seleccione el botón Archivo nuevo en la barra lateral de Visual Studio Code.
Asegúrese de que el nombre del archivo finalice con .al. En este ejemplo, es posible que desee usar el nombre CustomerRewardsWizard.Page.al.
Agregue el código a la página. Puede copiar el siguiente código y pegarlo en el archivo CustomerRewardsWizard.Page.al.
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;
}