@business-nxt/app-messaging
v2.0.0
Published
Helper library to build applications for Business NXT
Readme
@business-nxt/app-messaging
Helper library to build applications for Business NXT
Listen for changes from Business NXT
Your app and Business NXT communicate using postMessage back and forth. This means that you have to listen for messages with a messageType set.
The message types Business NXT will post are selection-state and edit-session.
import type { Message } from "@business-nxt/app-messaging";
window.addEventListener("message", (event) => {
const data = event.data as Message;
switch (data?.messageType) {
case "selection-state":
// do something as selection changed
break;
case "edit-session":
// do something as the session have changed edit mode
break;
}
});Request the current selection state
import { SendMessage } from "@business-nxt/app-messaging";
const selection = await SendMessage({ messageType: "selection-state-request" });selection
{
"messageType": "selection-state",
"id": "3dc32970-c15e-4227-84dc-0f8c3bba7e13",
"table": "associate",
"focusedRow": {
"associateNo": 9
},
"selectedRows": [{ "associateNo": 7 }, { "associateNo": 8 }]
}Request a table refresh
This will refresh the order table in the current layout
import { SendMessage } from "@business-nxt/app-messaging";
const refreshResponse = await SendMessage({
messageType: "refresh-data-request",
table: "order",
});refreshResponse
{
"messageType": "ok"
"id": "3dc32970-c15e-4227-84dc-0f8c3bba7e13",
}Request the current edit session state
import { SendMessage } from "@business-nxt/app-messaging";
const editSessionStatus = await SendMessage({
messageType: "edit-session-request",
});editSessionStatus
{
"messageType": "edit-session",
"id": "3dc32970-c15e-4227-84dc-0f8c3bba7e13",
"editing": true
}