Saturday, June 22, 2024

Dependency publishing Option - Optimize your deployment for big projects

 Hello Frieds,

Well – you do have the “dependencyPublishingOption” in the launch.json, which has 3 options:

Consider the scenario where you have multiple applications within an environment, designated as the Parent app and Child App A.

 

  • Parent App: This application does not have any dependencies.
  • Child App A: This application depends on the Parent app.

 

Problem Statement:

When deploying the Parent app in Business Central, should you reinstall all dependent apps (like Child App A)? If so, how can this process be configured to occur automatically?









Solution: 

Using the dependencyPublishingOption Property in launch.json

The dependencyPublishingOption property in the launch.json file is used to manage how dependent apps are handled during deployment. It offers three options:

 

  1. Default: Rebuilds and publishes all dependent apps.
  2. Ignore: Skips dependency publishing. Use this option cautiously, as it may break interdependent apps.
  3. Strict: Fails the publishing process if there are any installed extensions dependent on the root folder. (Publishing will fail if the project has apps that not part of the workspace and depend on it) - Not applicable at in case where we are not using workspace option.

I like the default setting – something it takes a little longer to include all dependencies in the compile – but at least you’re checking all dependencies .. So that must be good ðŸ™‚But, in some cases – especially in case of big apps with many objects – you might want to avoid unnecessary recompiles of dependent apps.. .  (for big project we can use Ignore option in dependency publish to avoid more wait time)

Friday, June 21, 2024

ErrorInfo Object Variable - Show the action message on error message

Hello Friends,

Developers can now set the Title property on Error dialogs that are presented to the user to enrich issue description. On top of that, using the ErrorInfo object, developers can add up to three custom actions that will be displayed on the Error dialog to provide users with corrective actions. This can be achieved by calling the AddAction method on the ErrorInfo object, which can be passed to AL methods that support ErrorInfo such as Error, TestField, FieldError, and others.

The AddAction method accepts three parameters:

  • Caption: The text string that appears as the caption of the action in the error UI.
  • CodeunitID: The ID of the Codeunit to run when the action is initiated from the error UI. The codeunit should contain at least one global method to be called by the error action. The global method must have an ErrorInfo data type parameter for accepting the ErrorInfo object.
  • Method Name: The name of the method in the Codeunit, which is specified by the CodeunitID parameter, that you want to run for the action.


One more useful ErrorInfo variable we can use for provide ERROR Message with actions

we can have multiple actions on error message itself to open relevant setup or master page

this will very convenient for user to Navigate to correct page for fixing any issue
















in above error there are two action showing Open Gen. Journal Template & Open Source Code Setup
 
this can possible using ErrorInfo variable
 
Sample Code:

codeunit 75030 INT_Sample_ErrorInfo
{


    trigger OnRun()
    var
        GenJournalLine: Record "Gen. Journal Line";
        ErrorInfo: ErrorInfo;
        SameSourceCodeErr: Label 'Journal Source Code %1 is same as Source Code set
for Purcase/Sales documents. This is not allowed when using deferrals.
If you want to use this journal for deferrals, please update Source Codes
on Gen Journal Template and generate line again.', Comment = '%1->Source Code';
        OpenGenJournalTemplateDescTxt: Label 'Open Gen. Journal Template page to
update Source code.';
        OpenSourceCodeSetupDescTxt: Label 'Open Source Code Setup page to check
Source code setup.';
    begin
        ErrorInfo.ErrorType(ErrorType::Client);
        ErrorInfo.Verbosity(Verbosity::Error);
        ErrorInfo.Message(StrSubstNo(SameSourceCodeErr, GenJournalLine."Source Code"));
        ErrorInfo.TableId(GenJournalLine.RecordId.TableNo);
        ErrorInfo.RecordId(GenJournalLine.RecordId);
        ErrorInfo.AddAction('Open Gen. Journal Template', Codeunit::"INT_Sample_ErrorInfo",
'ShowGenJournalTemplate', OpenGenJournalTemplateDescTxt);
        ErrorInfo.AddAction('Open Source Code Setup', Codeunit::"INT_Sample_ErrorInfo",
'ShowSourceCodeSetup', OpenSourceCodeSetupDescTxt);
        Error(ErrorInfo);
    end;

    procedure ShowGenJournalTemplate(ErrorInfo: ErrorInfo)
    var
        GenJournalTemplate: Record "Gen. Journal Template";
        GenJournalLine: Record "Gen. Journal Line";
        GeneralJournalTemplates: Page "General Journal Templates";
        RecordRef: RecordRef;
    begin
        RecordRef := ErrorInfo.RecordId.GetRecord();
        RecordRef.SetTable(GenJournalLine);
        GenJournalTemplate.SetRange(Name, GenJournalLine."Journal Template Name");
        GeneralJournalTemplates.SetTableView(GenJournalTemplate);
        GeneralJournalTemplates.RunModal();
    end;

    procedure ShowSourceCodeSetup(ErrorInfo: ErrorInfo)
    var
        SourceCodeSetup: Page "Source Code Setup";
    begin
        SourceCodeSetup.RunModal();
    end;
}


Stop using the Error() function in Business Central - Error Message Handler & Error Message Management

 Hello Friends,

Stop using the Error() function in Business Central.


A better approach when working with long processes, like posting, is to use these codeunits:

- "Error Message Handler".
- "Error Message Management".

They allow to log every error in a process and show them at the end.

Benefits.

1) Modern error.

It’s not just an error message. It can show related records to the error and add recommended actions.

2) Different message types.

You can show errors, warnings, messages, testfields, fielderrors, and more.

3) List of errors.

By showing a list of errors at the end, users don’t have to fix them one at a time.

Have a look at the base app for more examples:

Sales Header → SendToPosting
E-Invoice Mgt. → CheckSalesDocument

PS. Did you know about this approach?