This is a Svelte + Vite + Typescript template to be integrated in Business Central as a ControlAddIn. The bundled build result is the javascript source that can be used by BC.
npm install (requires NodeJS to be installed).npm run start to run the Project or npm run build to just build the Project.<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 a startup.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 from '@floriannoever/bc-controladdin-helper';
function someGlobalFunction() {
window.alert('Hello from the control add-in!');
}
ALHelper class:ALHelper.makeFunctionAccessible(someGlobalFunction);
controladdin "PTE MyControlAddIn"
{
Scripts = './addins/myproject.js';
procedure SomeGlobalFunction();
}
The template supports calling Events that are defined in the ControlAddIn file in the BC Project. For this you need to follow these steps:
controladdin "PTE MyControlAddIn"
{
Scripts = './addins/myproject.js';
event OnControlReady(Message: Text; CurrDateTime: Text);
}
import ALHelper from '@floriannoever/bc-controladdin-helper';
const datetime = new Date(Date.now());
ALHelper.invokeEvent('OnControlReady', 'Control Ready Event. Time: ', datetime.toLocaleTimeString());
// or skipping event if BC Environment is busy (operation is running)
ALHelper.invokeEventSkipBusy('OnControlReady', 'Control Ready Event. Time: ', datetime.toLocaleTimeString());
Note that the First parameter of the invokeEvent function is the name of the Event in your BC Project. All other parameters are the variables you want to call the event in BC with invokeEvent('name', param1, param2). If you have your data in form of an array just use the spread operator invokeEvent('name', ...yourarray)