Hero

Granting Access

To get started with NXT Triggers with a Visma Business NXT Customer, you need to grant it access. Go to Connect Application and add isv_nxt_triggers as a user with connected application activated.

You also have to make sure that you are a user with supervisor rights in the Business NXT customer.

Creating a Trigger

To create or edit a trigger, open NXT Triggers and select the company you want to work with under triggers. Then press + Create Trigger and select the table and event you want to trigger on.

Your first trigger

When you create a new trigger, you will be met with a code editor. Here you can write your trigger code in TypeScript.

All triggers must export a default function, which is an async function that takes an object with the following properties.

PropertyDescription
eventDetails about the event that triggered the trigger. Read about the event object.
dbThis is a minimal client to interact with the Business NXT client. This is automatically authenticated to interact with the client that sent the event.
createGraphQLClientA function that creates a GraphQL client using the VISMA_CLIENT_ID and VISMA_CLIENT_SECRET you’ve defined under settings.
printOrderDocumentCreates a PDF document from an order document using the NXT Ninja Document Printer. This allows for more customizations than the regular document printer in Business NXT.
sendEmailSends an email using Postmark. Required properties are { To: "", From: "", Subject: "", TextBody: ""}. This requires the secret POSTMARK to be set.
sendToPrinterSends a document to a printer using PrintNode.com. Required properties are { printerId: 0, document: "base64 data of PDF"}. The PrintNode API token must be set as PRINTNODE under settings.
useIndepotentA function that ensures that a function is only run once, even if it’s called multiple times. The first argument is the key, and the second is the function. The value returned from the function must be serializable to JSON, or undefined.
changedColumnsAn object with the columns that have changed in the event. This is undefined for DELETE events.
hasColumnChangedA function that checks if a column has changed. This takes the column name as a parameter and returns true or false. Will always return false for DELETE events.

About indepotency

A big difference between SQL triggers and NXT triggers is that a NXT trigger might be retried. Since we are running in the cloud, we can’t guarantee that the services we are calling are idempotent. To ensure that a part of a trigger is only run once, even if it’s called multiple times, you can use the useIndepotent function.

useIndepotent
// the key must be unique for the function you are running
const result = await useIndepotent("unique-sample-key", async () => {
  const value = await someAsyncFunction();
  return value; // Must be serializable to JSON
});

Example usage in triggers

Base Trigger

This is the starting point for your new trigger. It logs the event object to the console, and by using the debugger you can see the output from the trigger.