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.