Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianNoeverGOB committed Aug 20, 2024
1 parent 7ed5f49 commit a169dff
Show file tree
Hide file tree
Showing 22 changed files with 8,164 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
"@babel/preset-env",
[
"@babel/preset-react",
{
"runtime": "automatic"
}
],
"@babel/preset-typescript"
]
}
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SOME_SECRET_KEY=somevalue
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ReactBC
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.

## How to use the template
1. Clone this Repository
2. Open a Terminal in the root of the Project and execute `npm install` (requires NodeJS to be installed).
3. In the Terminal run `npm run start` to run the Project or `npm run build` to just build the Project.
4. 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 a `startup.js` file.

## 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:
1. Import ALHelper class `import ALHelper from 'Utils/alHelper';`
2. Have a function that you want to make accessible for AL Code:
```javascript
function someGlobalFunction() {
window.alert('Hello from the control add-in!');
}
```
3. Make that function accessible using the `ALHelper` class:
```javascript
ALHelper.makeFunctionAccessible(someGlobalFunction);
```
4. In the ControlAddIn of your BC Project, define the Function (Note that first letter is capital):
```c#
controladdin "PTE ReactBC"
{
Scripts = '.scripts/react-bc.bundle.js';

procedure SomeGlobalFunction();
}
```
5. 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:
1. Add the event you want to the ControlAddIn in your BC Project:
```c#
controladdin "PTE ReactBC"
{
Scripts = '.scripts/react-bc.bundle.js';
event OnControlReady(Message: Text; CurrDateTime: Text);
}
```
2. Invoke the event in the React Project:
```javascript
const datetime = new Date(Date.now());
ALHelper.invokeEvent('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 and the second parameter is an array of the parameters you want to call the event in BC with.
Loading

0 comments on commit a169dff

Please sign in to comment.