@floriannoever/bc-controladdin-helper
v1.0.5
Published
Helper for invoking AL events for a controladdin from JS/TS
Maintainers
Readme
BC ControlAddIn Helper
Helper for invoking AL events or making JS/TS functions available for AL ControlAddIns to call.
How to use the package
- Install via
npm install --save @floriannoever/bc-controladdin-helper - Import the ALHelper class
import ALHelper from '@floriannoever/bc-controladdin-helper'; - Use the available function as mentioned below
How to Call Functions from AL code
The template supports making functions public to be callable from the BC ControlAddIn. For this you need to follow these steps:
- 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
ALHelperclass:ALHelper.makeFunctionAccessible(someGlobalFunction); - In the ControlAddIn of your BC Project, define the Function (Note that first letter is capital):
controladdin "PTE MyControlAddIn" { Scripts = './addins/myproject.js'; procedure SomeGlobalFunction(); } - Call the procedure like you would normally do using the ControlAddIn
How to call an AL Event from React
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 MyControlAddIn" { Scripts = './addins/myproject.js'; event OnControlReady(Message: Text; CurrDateTime: Text); } - Invoke the event in your Project:
Note that the First parameter of theconst 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());invokeEventfunction is the name of the Event in your BC Project. All other parameters are the variables you want to call the event in BC withinvokeEvent('name', param1, param2). If you have your data in form of an array just use the spread operatorinvokeEvent('name', ...yourarray)
