Tuesday, 11 March 2025

How to manage Manufacturing documents in Business Central

 

Business Value

Managing the manufacturing-related documents like drawings, inspection reports, and work instructions is important for an efficient production process. The new document attachment feature in Business Central digitizes the management of documents by associating them directly with production BOMs, routings, and orders.

 

Feature Details

In Business Central 2025 Wave 1 release, document attachments are now available across several pages related to manufacturing. This enhancement enables users to attach, view, and manage documents directly from production-related records so that users can get access to necessary files.

 

Where Can You Use Document Attachments?

 Now, multiple places will see the Document Attachment FactBox added:

 


Production BOMs:

Production BOM (Page 99000786)

Production BOMs (Page 99000787)

 

Routings:

 Routing (Page 99000766)

 Routing List (Page 99000764)

 

Production Orders:

Simulated Production Order (Page 99000912)

Simulated Production Orders (Page 9323)

Planned Production Order (Page 99000813)

Planned Production Orders (Page 9324)

Firm Planned Prod. Order (Page 99000829)

Firm Planned Prod. Orders (Page 9325)

Released Production Order (Page 99000831)

Released Production Orders (Page 9326)

Finished Production Order (Page 99000867)

Finished Production Orders (Page 9327)

Production Order List (Page 99000815)

 

Also, the Attachment Action gives you access to document attachments from production order lines on the following pages:



         Simulated Prod. Order Lines (Page 99000913)

 Planned Prod. Order Lines (Page 99000814)

 Firm Planned Prod. Order Lines (Page 99000830)

 Released Prod. Order Lines (Page 99000832)

 Finished Prod. Order Lines (Page 99000868)

 

New Attachment Flow Control

A Flow to Production Trx toggle has now been included on the Attached Documents page. This gives control to users to define how attachments related to items, production BOMs, or routings flow to production order lines, so only relevant documents are rolled over.

 


Limitations to Be Aware Of

 Component attachments aren't supported.

 Production BOM versions or routing versions do not have any attachments.

 

Conclusions

The improvements will literally allow manufacturers using Business Central to better document management and accessibility.


Monday, 10 March 2025

How to Preview PDF Attachments Directly in Business Central Web Client

 Overview

In the upcoming Business Central 2025 Wave 1 release, Microsoft has introduced a new feature that allows users to preview PDF attachments directly in the web client. Previously, when users clicked on an attachment in Business Central, the file would download and then open in a separate application. With this new enhancement, users can now view attachments seamlessly within the Business Central interface without downloading them

Example: Viewing Email Attachments in Business Central

One practical use case for this feature is within the "Compose an Email" page. When adding a file to the Attachments tab, previously, clicking on the file name would download it. Now, we can add a "View File" action that enables direct preview in the same window.

Implementation using Page Extension

Below is an AL page extension that adds a "View File" action to the Email Attachments page. This action allows users to preview attachments without downloading them.


pageextension 69987 "MPA Email Attachments Ext" extends "Email Attachments"

{

    actions

    {

        addlast(Processing)

        {

            action(ViewFile)

            {

                ApplicationArea = All;

                Caption = 'View File';

                Image = View;

 

                trigger OnAction()

                var

                    TenantMedia: Record "Tenant Media";

                    FileInStream: InStream;

                begin

                    // Fetch the attachment from the "Tenant Media" table

                    TenantMedia.SetAutoCalcFields(Content);

                    TenantMedia.Get(Rec.Data.MediaId());

                    if TenantMedia.Content.HasValue() then begin

                          TenantMedia.Content.CreateInStream(FileInStream);

                          // Use the new feature to open the file in a preview window

                          File.ViewFromStream(FileInStream, Rec."Attachment Name", true);

                    end;

                end;

            }

        }

    }

}


o   The new function File.ViewFromStream(FileInStream, Rec."Attachment Name", true); is used.

o   This opens the file directly in the Business Central web client preview window.










 

Similarly, Added to Email Scenario Attachments

I have also applied the same functionality to the Email Scenario Attachments page.





GitHub Link ViewFile

Sunday, 9 March 2025

How to Check When a Business Central Service Was Last Restarted

 

One of my colleagues recently asked how to determine the last restart time of a Business Central service. If you've ever needed to check when a Business Central service was last restarted, PowerShell provides a quick and efficient way to do this.

The PowerShell Script

The following PowerShell command retrieves the restart time of all running Microsoft Dynamics 365 Business Central services:

Get-CimInstance -ClassName Win32_Service |

    Where-Object { $_.Name -like "MicrosoftDynamicsNavServer*" } |

    Select-Object Name, ProcessId, @{Name="Last Restarted";Expression={(Get-Process -Id $_.ProcessId).StartTime}}

Explanation of the Script:

  • Get-CimInstance -ClassName Win32_Service – Retrieves all Windows services running on the system.
  • Where-Object { $_.Name -like "MicrosoftDynamicsNavServer*" } – Filters out only those services related to Business Central (previously NAV) by name.
  • Select-Object Name, ProcessId, @{Name="Last Restarted";Expression={(Get-Process -Id $_.ProcessId).StartTime}} – Extracts the service name, process ID, and retrieves the start time of the corresponding process, which indicates when the service was last restarted.

Running the Script

Simply open PowerShell with administrator privileges and run the above command. It will output a list of Business Central services along with their last restart time.




Saturday, 8 March 2025

How to Display the Latest 10 Posted Sales Invoice Lines in a Sales Order FactBox

 

In Microsoft Dynamics 365 Business Central, users often need quick access to historical sales invoice data while working on Sales Orders. A common requirement is to display the latest 10 posted sales invoice lines related to a specific Sales Order Line. This blog post walks through how to create a FactBox that dynamically updates based on the selected Sales Order Line.


Understanding the Requirement

We need to:

1.      Create a FactBox that displays Posted Sales Invoice Lines.

2.      Link the FactBox to Sales Order Lines, ensuring that when a user selects a Sales Order Line, the FactBox updates.

3.      Limit the display to only the last 10 lines for better readability.


Step 1: Creating the FactBox

We define a ListPart Page that retrieves and displays the last 10 posted invoice lines.

page 50100 "MPA Posted SI Lines Factbox"

{

    PageType = ListPart;

    SourceTable = "Sales Invoice Line";

    Caption = 'Posted Sales Invoice Lines';

    RefreshOnActivate = true;

    SourceTableTemporary = true;

    SourceTableView = SORTING("Posting Date", "Line No.") ORDER(Descending);

    ApplicationArea = All;

    DeleteAllowed = false;

 

    layout

    {

        area(content)

        {

            repeater(Group)

            {

                field("Document No."; Rec."Document No.") { ApplicationArea = All; }

                field("Line No."; Rec."Line No.") { ApplicationArea = All; }

                field(Description; Rec.Description) { ApplicationArea = All; }

                field(Quantity; Rec.Quantity) { ApplicationArea = All; }

                field("Unit Price"; Rec."Unit Price") { ApplicationArea = All; }

                field(Amount; Rec.Amount) { ApplicationArea = All; }

            }

        }

    }

 

    trigger OnFindRecord(Which: Text): Boolean

    begin

        exit(LoadDataFromOnFindRecord);

    end;

 

    procedure LoadDataFromOnFindRecord(): Boolean

    var

        SalesInvoiceLines: Record "Sales Invoice Line";

        NoFilter: Code[20];

        Counter: Integer;

        CurrentFilterGroup: Integer;

    begin

        Counter := 0;

 

        CurrentFilterGroup := Rec.FilterGroup();

        Rec.FilterGroup(4);

        NoFilter := Rec.GetFilter("No.");

        Rec.FilterGroup(CurrentFilterGroup);

        Rec.Reset();

        Rec.DeleteAll();

        SalesInvoiceLines.Reset();

        SalesInvoiceLines.SetRange("No.", NoFilter);

        SalesInvoiceLines.SetCurrentKey("Posting Date", "Line No.");

        SalesInvoiceLines.Ascending(false);

 

        if SalesInvoiceLines.FindSet() then

            repeat

                Rec := SalesInvoiceLines;

                Rec.Insert();

                Counter += 1;

            until (Counter >= 10) or (SalesInvoiceLines.Next() = 0);

 

        exit(not Rec.IsEmpty());

    end;

}

How This Works

✔️ Uses a temporary table to ensure efficient data handling.
✔️ Sorts invoice lines in descending order to get the most recent lines first.
✔️ Limits results to 10 lines using a counter.


Step 2: Extending the Sales Order Page

Now, we integrate the FactBox into the Sales Order Page and link it to the Sales Order Lines.

pageextension 50101 “MPA Sales Order Ext” extends "Sales Order"

{

    layout

    {

        addfirst(factboxes)

        {

            part(PostedSalesInvoiceLinesFactbox; "MPA Posted SI Lines Factbox")

            {

                ApplicationArea = All;

                SubPageLink = "No." = field("No.");

            Provider = SalesLines;

            }

        }

    }

}

How This Works

✔️ Links FactBox to Sales Order Lines using the No. field.
✔️ Ensures the FactBox updates dynamically when the user selects a different Sales Order Line.


Final Outcome

  • The FactBox will now display the latest 10 posted sales invoice lines linked to the selected Sales Order Line.
  • Every time a user navigates through different Sales Order Lines, the FactBox updates accordingly.



The code is available at: GitHub Repository.

Friday, 28 February 2025

How Can We Update a Field Upon Workflow Approval in Business Central?

 

Business Central’s workflows automate actions based on workflow responses. One common requirement is to update a specific field once a workflow is approved.

Updating the Description Field in General Journal Batch Workflow.

In this scenario, when a General Journal Batch is approved, the Description field should be updated with "Account Type + Account No.". This can be achieved by leveraging Business Central’s approval response mechanism.

Step 1: Identify the Approval Response Code Path

  • The approval process navigates through codeunit 1521 and then to codeunit 1535.
  • Within codeunit 1535, there is a publisher OnApproveApprovalRequestsForRecordOnBeforeApprovalEntryToUpdateModify.
  • This publisher allows modify records upon approval.

Step 2: Implement the Code to Update the Description Field

Use the following AL code to subscribe to the event and update the Description field:

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Approvals Mgmt.", OnApproveApprovalRequestsForRecordOnBeforeApprovalEntryToUpdateModify, '', false, false)]

local procedure "Approvals Mgmt._OnApproveApprovalRequestsForRecordOnBeforeApprovalEntryToUpdateModify"(var ApprovalEntryToUpdate: Record "Approval Entry")

var

    RecRef: RecordRef;

    GenJournalBatch: Record "Gen. Journal Batch";

    GenJournalLine: Record "Gen. Journal Line";

begin

    if not RecRef.Get(ApprovalEntryToUpdate."Record ID to Approve") then

        exit;

 

    case RecRef.Number of

        Database::"Gen. Journal Batch":

            begin

                RecRef.SetTable(GenJournalBatch);

                GenJournalLine.Reset();

                GenJournalLine.SetRange("Journal Template Name", GenJournalBatch."Journal Template Name");

                GenJournalLine.SetRange("Journal Batch Name", GenJournalBatch."Name");

                if GenJournalLine.FindSet() then

                    repeat

                        GenJournalLine.Description := format(GenJournalLine."Account Type") + ' ' + GenJournalLine."Account No.";

                        GenJournalLine.Modify();

                    until GenJournalLine.Next() = 0;

            end;

 

        Database::"Gen. Journal Line":

            begin

                RecRef.SetTable(GenJournalLine);

                if GenJournalLine.FindSet() then

                    repeat

                        GenJournalLine.Description := 'Set the value as per your requirement';

                        GenJournalLine.Modify();

                    until GenJournalLine.Next() = 0;

            end;

    end;

end;

Step 3: Deploy and Test the Code

1.      Deploy the extension containing the event subscriber.

2.      Submit a General Journal Batch for approval.

3.      Approve the batch and verify that the Description field is updated.



Conclusion

This approach can be extended to other workflows and responses by identifying the proper publisher.

 


Saturday, 15 February 2025

Is it Possible to Set "Receive" by Default or Disable "Invoice" Options in Purchase Order?

 

In Business Central, purchase orders typically allow users to either receive items, invoice them, or both. However, in some cases, businesses may want to enforce a workflow where only the "Receive" option is available by default, preventing users from invoicing.

Solution: Restrict Invoicing via User Setup

You can achieve this by modifying the User Setup configuration:

1.      Navigate to User Setup in Business Central.

2.      Locate the user for whom you want to restrict invoicing.

3.      Set Purch. Invoice Posting Policy to Prohibited.

 

A screenshot of a computer

AI-generated content may be incorrect.

 

Effect of This Setting

  • When the user attempts to post a purchase order, Business Central will prompt a confirmation to post only the Receipt.

 


Similar Functionality for Sales and Service Orders:

The same restriction can also be applied to Sales Orders and Service Orders by setting the respective Invoice Posting Policy to Prohibited in the User Setup.