Skip to content
Developerhome
X3

Custom Node Script Operations

  Less than to read

In this page we demonstrate making a custom GraphQL mutation to reach a function you’ve created in Xtrem. This allows you to use this function in a GraphQL mutation for a standard node.

Create a Custom Node Script

To create a mutation based on an Xtrem function you’ve written, begin with the API Operation (GESAPIOPE) form found at Development > Operations and press the Create (+) button on the far right to create an operation. Select the Mutation type Custom and the Operation Method Node Script.

Note: This Node Script operation method is available only for Custom mutations.

Note: For regular custom X3 scripts, select Mutation type Custom and Operation Method Script instead, see Subprograms - Create your operation.

For this example, assume you want an API to extend functionality of this node to get the current currency rate, using the existing getCurrencyRates function you’ve written in Xtrem. The operation CURRENCY is selected, and select Main node name Currency. Create the GraphQL operation and name it getCurrencyRates.

Operation.named

General Characteristics

The Module field will be suggested automatically, depending on the module the Node is located in. As this is a Currency node, fill Module field with Supervisor. To make the mutation active after saving, make sure the Active checkbox is ticked.

The mandatory fields Function Package and Function Path must be filled in.

  • Locate the path where the function is located in Xtrem. In this case, choose sage/x3-master-data from the search dropdown.
  • Type functions.getCurrencyRates manually to match our operation.

Operations.characteristics

Node Script

Scrolling down to the Variables section of the form, select it and click the Node Script subsection. Define the name and type of the input and output variables your mutation will expect. In this example, choose code, a string, as input, and value, a string, as output.

Node Script Variables

  • Verify the integrity of your choices and complete the operation with the Verify (checkmark) button far right.

Now you can generate the script in Xtrem using:

npm script generate

Verify

Once the custom node script has been generated, go into Xtrem to see the generated Typescript:

Node Scripts