ReactBC is a React template to be integrated in Business Central as a ControlAddIn. The bundled build result is the javascript source that can be used by BC.
- Clone this Repository
- Open a Terminal in the root of the Project and execute
npm install
(requires NodeJS to be installed). - In the Terminal run
npm run start
to run the Project ornpm run build
to just build the Project. - The build result is
<projectname>.bundle.js
. You can copy this file into the BC Workspace and use it as a ControlAddIn like you normally would. There is no need for astartup.js
file.
The template supports making functions public to be callable from the BC ControlAddIn. For this you need to follow these steps:
- Import ALHelper class
import ALHelper from 'Utils/alHelper';
- Have a function that you want to make accessible for AL Code:
function someGlobalFunction() { window.alert('Hello from the control add-in!'); }
- Make that function accessible using the
ALHelper
class:ALHelper.makeFunctionAccessible(someGlobalFunction);
- In the ControlAddIn of your BC Project, define the Function (Note that first letter is capital):
controladdin "PTE ReactBC" { Scripts = '.scripts/react-bc.bundle.js'; procedure SomeGlobalFunction(); }
- Call the procedure like you would normally do using the ControlAddIn
The template supports calling Events that are defined in the ControlAddIn file in the BC Project. For this you need to follow these steps:
- Add the event you want to the ControlAddIn in your BC Project:
controladdin "PTE ReactBC" { Scripts = '.scripts/react-bc.bundle.js'; event OnControlReady(Message: Text; CurrDateTime: Text); }
- Invoke the event in the React Project:
Note that the First parameter of the
const datetime = new Date(Date.now()); ALHelper.invokeEvent('OnControlReady', ['Control Ready Event. Time: ', datetime.toLocaleTimeString()]);
invokeEvent
function is the name of the Event in your BC Project and the second parameter is an array of the parameters you want to call the event in BC with.