API - SaaS 18 insert gen journal balancing account


Is there a way to create a gen journal line with the balancing account as when I tried with the standard code sample from MS it doesn’t work, either journalLines end point or $batch end point. Have others experience this or can someone share sample code?


Yes, it is possible to create a general journal line with the balancing account in Business Central. The standard code samples provided by Microsoft should work, but it’s important to ensure that the code is implemented correctly.

To create a general journal line with the balancing account, you need to specify the relevant fields and values when constructing the journal line record. Here’s a sample code snippet that demonstrates the process:

var journalLine: Record “General Journal Line”;

journalLine.“Document Type” := journalLine.“Document Type”::“Gen. Journal”;
journalLine.“Journal Template Name” := ‘GENJOURNAL’;
journalLine.“Journal Batch Name” := ‘JNL01’;
journalLine.“Account No.” := ‘12345’; // Enter the desired account number
journalLine.“Bal. Account No.” := ‘67890’; // Enter the balancing account number
journalLine.Amount := 100.00; // Enter the desired amount

In the above code, make sure to replace ‘GENJOURNAL’ with the name of the appropriate journal template and ‘JNL01’ with the desired journal batch name. Also, provide the correct account numbers and amount as per your requirements.

If the standard code samples are not working for you, it could be due to a configuration issue or some other factor specific to your environment. I recommend reviewing your code implementation, ensuring that you have the necessary permissions, and verifying that all the required fields and values are correctly set.

If you continue to face difficulties or need further assistance, it may be helpful to provide more specific details about the error or issue you are encountering. This will allow others to provide more targeted guidance or share additional sample code that addresses your specific scenario.