Page 6344 Sust. ESG Range Periods

Sustainability, Microsoft.Sustainability.ESGReporting

src/Apps/W1/Sustainability/app/src/ESGReporting/SustESGRangePeriods.Page.al225 lines, Copyright (c) Microsoft Corporation. MIT

// ------------------------------------------------------------------------------------------------// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License. See License.txt in the project root for license information.// ------------------------------------------------------------------------------------------------namespace Microsoft.Sustainability.ESGReporting;using Microsoft.Integration.Dataverse;using Microsoft.Sustainability.Setup;page 6344 "Sust. ESG Range Periods"{    Caption = 'ESG Range Periods';    Editable = false;    PageType = List;    UsageCategory = Lists;    ApplicationArea = Basic, Suite;    SourceTable = "Sust. ESG Range Period";    layout    {        area(content)        {            repeater(Control1)            {                ShowCaption = false;                field("No."; Rec."No.")                {                    ApplicationArea = Basic, Suite;                    ToolTip = 'Specifies the value of the No. field.';                }                field(Description; Rec.Description)                {                    ApplicationArea = Basic, Suite;                    ToolTip = 'Specifies the value of the Description field.';                }                field("Period Starting Date"; Rec."Period Starting Date")                {                    ApplicationArea = Basic, Suite;                    ToolTip = 'Specifies the value of the Period Starting Date field.';                }                field("Period Ending Date"; Rec."Period Ending Date")                {                    ApplicationArea = Basic, Suite;                    ToolTip = 'Specifies the value of the Period Ending Date field.';                }                field("Coupled to Dataverse"; Rec."Coupled to Dataverse")                {                    ApplicationArea = All;                    Visible = SustDataverseIntEnabled;                }            }        }        area(factboxes)        {            systempart(Links; Links)            {                ApplicationArea = RecordLinks;                Visible = false;            }            systempart(Notes; Notes)            {                ApplicationArea = Notes;                Visible = false;            }        }    }    actions    {        area(Navigation)        {            group(ActionGroupCRM)            {                Caption = 'Dataverse';                Visible = SustDataverseIntEnabled;                action(CRMGotoRangePeriod)                {                    ApplicationArea = Suite;                    Caption = 'Range Period';                    Image = CoupledItem;                    ToolTip = 'Open the coupled Dataverse range period.';                    trigger OnAction()                    var                        CRMIntegrationManagement: Codeunit "CRM Integration Management";                    begin                        CRMIntegrationManagement.ShowCRMEntityFromRecordID(Rec.RecordId());                    end;                }                action(CRMSynchronizeNow)                {                    AccessByPermission = TableData "CRM Integration Record" = IM;                    ApplicationArea = Suite;                    Caption = 'Synchronize';                    Image = Refresh;                    ToolTip = 'Send or get updated data to or from Dataverse.';                    trigger OnAction()                    var                        ESGRangePeriod: Record "Sust. ESG Range Period";                        CRMIntegrationManagement: Codeunit "CRM Integration Management";                        ESGRangePeriodRecordRef: RecordRef;                    begin                        CurrPage.SetSelectionFilter(ESGRangePeriod);                        ESGRangePeriod.Next();                        if ESGRangePeriod.Count = 1 then                            CRMIntegrationManagement.UpdateOneNow(ESGRangePeriod.RecordId())                        else begin                            ESGRangePeriodRecordRef.GetTable(ESGRangePeriod);                            CRMIntegrationManagement.UpdateMultipleNow(ESGRangePeriodRecordRef);                        end                    end;                }                group(Coupling)                {                    Caption = 'Coupling', Comment = 'Coupling is a noun';                    Image = LinkAccount;                    ToolTip = 'Create, change, or delete a coupling between the Business Central record and a Dataverse record.';                    action(ManageCRMCoupling)                    {                        AccessByPermission = TableData "CRM Integration Record" = IM;                        ApplicationArea = Suite;                        Caption = 'Set Up Coupling';                        Image = LinkAccount;                        ToolTip = 'Create or modify the coupling to a Dataverse range period.';                        trigger OnAction()                        var                            CRMIntegrationManagement: Codeunit "CRM Integration Management";                        begin                            CRMIntegrationManagement.DefineCoupling(Rec.RecordId());                        end;                    }                    action(DeleteCRMCoupling)                    {                        AccessByPermission = TableData "CRM Integration Record" = D;                        ApplicationArea = Suite;                        Caption = 'Delete Coupling';                        Enabled = CRMIsCoupledToRecord;                        Image = UnLinkAccount;                        ToolTip = 'Delete the coupling to a Dataverse range period.';                        trigger OnAction()                        var                            ESGRangePeriod: Record "Sust. ESG Range Period";                            CRMCouplingManagement: Codeunit "CRM Coupling Management";                            RecRef: RecordRef;                        begin                            CurrPage.SetSelectionFilter(ESGRangePeriod);                            RecRef.GetTable(ESGRangePeriod);                            CRMCouplingManagement.RemoveCoupling(RecRef);                        end;                    }                }                action(ShowLog)                {                    ApplicationArea = Suite;                    Caption = 'Synchronization Log';                    Image = Log;                    ToolTip = 'View integration synchronization jobs for the Range Period table.';                    trigger OnAction()                    var                        CRMIntegrationManagement: Codeunit "CRM Integration Management";                    begin                        CRMIntegrationManagement.ShowLog(Rec.RecordId);                    end;                }            }        }        area(Promoted)        {            group(Category_Synchronize)            {                Caption = 'Synchronize';                Visible = SustDataverseIntEnabled;                group(Category_Coupling)                {                    Caption = 'Coupling';                    ShowAs = SplitButton;                    actionref(ManageCRMCoupling_Promoted; ManageCRMCoupling)                    {                    }                    actionref(DeleteCRMCoupling_Promoted; DeleteCRMCoupling)                    {                    }                }                actionref(CRMSynchronizeNow_Promoted; CRMSynchronizeNow)                {                }                actionref(ShowLog_Promoted; ShowLog)                {                }            }        }    }    trigger OnOpenPage()    var        SustainabilitySetup: Record "Sustainability Setup";        CRMIntegrationManagement: Codeunit "CRM Integration Management";    begin        CRMIntegrationEnabled := CRMIntegrationManagement.IsCRMIntegrationEnabled();        CDSIntegrationEnabled := CRMIntegrationManagement.IsCDSIntegrationEnabled();        if CRMIntegrationEnabled or CDSIntegrationEnabled then            SustDataverseIntEnabled := SustainabilitySetup.IsDataverseIntegrationEnabled();    end;    trigger OnAfterGetCurrRecord()    var        CRMCouplingManagement: Codeunit "CRM Coupling Management";    begin        if CRMIntegrationEnabled or CDSIntegrationEnabled then            CRMIsCoupledToRecord := CRMCouplingManagement.IsRecordCoupledToCRM(Rec.RecordId);    end;    var        CRMIntegrationEnabled: Boolean;        CDSIntegrationEnabled: Boolean;        CRMIsCoupledToRecord: Boolean;        SustDataverseIntEnabled: Boolean;}