Skip to content

Microsoft Busincess Central extension (Codeunit) to post General Journal Line

Notifications You must be signed in to change notification settings

jigneshkhatri/MBC-Gen-Journal-Line-Posting-CodeUnit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A small extension (Codeunit) to Post the Journal entries in Microsoft Business Central via OData API.

Prerequisites

  • Get access to the Sandbox environment (production environment will not work for development/compilation perspective) of Microsoft Business Central
  • Install Visual Studio Code

Setup

  • Clone this repository into your local system
  • Install MS AL extension in VS code as mentioned here - https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-get-started
  • Open the cloned repository folder in the VS code
  • Goto .vscode/launch.json and update the following fields:
    • serverInstance: Environment name of the MS Business Central
    • tenant: Tenant GUID of the MS Business Central account (Tip: You can find the Tenant GUID in the browser's URL when you login to your MS Business Central account)
    • environmentType: Must be Sandbox for development purposes
    • environmentName: Environment name of the MS Business Central
  • Save these changes, and download the AL Symbols from MS Business Central.
    • To download the AL Symbols, a dialog box will pop up automatically in the VS Code, using which you can download the AL Symbols.
    • Alternatively, if that dialog box doesn't appear, just restart the VS Code and that dialog will automatically appear if AL Symbols are not found in your current folder.
      • For the first time, it would ask to authenticate your user using Microsoft Extranet and would open the authentication page in the browser, just follow the steps as mentioned in the instructions during this process.

How to package this Codeunit?

  • Once the setup is done, and there are no errors in the project, open Command Palette in VS Code, and execute the following command
    • AL: package
  • By the time if packaging is successful, then *.app file will have been generated in the main folder of your project.
  • This *.app file is the final extension artifact that needs to be deployed on Microsoft Business Central.

How to install the extension (Codeunit) on Microsoft Business Central?

  • Login into your MS Business Central account.
  • Search and open Extension Management in the global search of Business Central (a search icon in the top bar).
  • Click on Manage > Upload Extension...
    • image
  • Select and upload the *.app file which is generated in the above steps.
  • Track the upload process in the Manage > Installation Status menu.
  • Once the installation process is Completed, then you can see this extension in the Installed Extensions card (Extension Management).

How to create and publish a Web Service for this Codeunit?

  • Once the extension is successfully installed, search and open Web Services in the global search of Business Central.
  • Click on the + New button in the top ribbon.
    • image
    • Select Codeunit as Object Type
    • Select 50101 as Object ID - This is the same ID that we have mentioned in the source code while declaring the Codeunit.
    • Write any meaningful name in the Service Name
    • Tick the Published checkbox against this new entry to publish this web service.

How to trigger this Codeunit using OData API?

  • Once the Web Service is published as per the above step, build the OData API URL in the below pattern:
    • https://api.businesscentral.dynamics.com/v2.0/<tenant id>/<environment name>/ODataV4/<service name>_<procedure name>?company=<company id>
      • Here the <service name> should be the name of the service that we have entered while creating the Web Service in the above step.
      • <procedure name> is the name of the procedure that we have created in the Codeunit. In our case, it would be PostGenJournalLine.
      • HTTP method: POST
  • Below is the sample cURL for this API:
    •   curl --location 'https://api.businesscentral.dynamics.com/v2.0/<tenant id>/<environment name>/ODataV4/<service name>_PostGenJournalLine?company=<company id>' \
        --header 'Content-Type: application/json' \
        --header 'Authorization: Bearer <auth token>' \
        --data '{
            "genJournalLineID": "<Journal line item GUID which needs to be posted>"
        }'
      

References:

About

Microsoft Busincess Central extension (Codeunit) to post General Journal Line

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages