Dynamics 365 Business Central is a comprehensive business management solution that helps organizations streamline their processes and improve overall efficiency.
One of the powerful features of D365 Business Central is the ability to customize dimensions, which are attributes you assign to entries for tracking and analyzing purposes.
Let’s start through the process of inserting a new custom dimension set entry while creating a new General Journal Line using AL code.
Steps to Insert a New Custom Dimension Set Entry
- Define the New Custom Dimension: For this example, First, ensure that this dimension exists in the Dimension table.
2. Create a New AL Codeunit: Add a new codeunit to your project. This codeunit will contain the logic to insert the custom dimension set entry and the general journal line.
Explanation of the Code:
- Create one Procedure “InsertDim” to call on Action which we will create on one page to run this Codeunit & Define variables as below to use in code.
2. Check if Dimension Value Code is exist or not, if not then insert Dimension Value Code with required Dimension Code.
3. Initialization: The GenJournalLine.Init() method initializes a new General Journal Line record.
4. Setting Basic Fields: We set various fields of the General Journal Line such as Journal Template Name, Journal Batch Name, Account Type, Account No., and Amount. & Insert Journal Line.
5. Custom Dimension: We initialize a Dimension Set Entry record, set the Dimension Code and Dimension Value Code to the custom dimension and value respectively.
6. Dimension Management: The DimensionManagement codeunit is used to get or create a Dimension Set ID based on the provided dimension entries.
7. Now Apply the same to Original Dimension Set Entry & Insert.
8. In the last modify GenJournalLine with same Dimension Set ID.
9. Deploy and Test: Deploy this code to your Business Central environment, and the new action on the General Journal page will allow you to insert a custom journal line with the specified dimension set entry.
Conclusion
Adding custom dimensions to General Journal Lines in Business Central using AL code provides powerful flexibility for tracking and analyzing data.
We covered the basics of inserting a new custom dimension set entry and a new General Journal Line. With this foundation, you can further customize and expand your AL code to meet specific business needs.
By leveraging the Dimension Management codeunit and understanding the structure of General Journal Lines, you can ensure accurate and efficient data entry within your environment.
Happy coding!