> For the complete documentation index, see [llms.txt](https://docs.monokot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.monokot.io/scripts/programming-examples/how-to-opc-ua-method.md).

# How to: OPC UA Method

The guide demonstrates how to define the arguments and the body of the OPC UA method.

{% hint style="warning" %}
Please note that calling the OPC UA method will immediately put the script module into demo mode
{% endhint %}

Open Monokot Server Administrator and double-click Scripts on the Server Explorer pane. Click New Expression and set the name CalcAdd for the expression that appears. Insert the following code into the expression code editor:

```javascript
// Special trigger "_callme", indicating a call to the OPC UA method
if (context.currentTrigger == '_callme') {
	// For example, let's add two numbers
	var tmp = context.inputArguments['a'].value + context.inputArguments['b'].value;
	context.outputArguments['result'].value = tmp;
}

// In this case, the value of the expression
// does not change
return MosUtils.doNothing;
```

Press Ctrl + Enter to apply the change in the code editor.

Go to the Method -> Input Arguments tab and click Add Argument. Enter the name (key) "a" for the input argument. In the same way, create an input argument named "b".

![](/files/6kVgQVtYKhYmPoB2A8MO)

Go to the Method -> Output Arguments tab and click Add Argument. Enter the name (key) "result" for the output argument.

![](/files/DAqLBcRX3purjUYqTC28)

In order for the changes to take effect on the server, click the Sync button or press F5. Now you can call the method using OPC UA client and see the result of its execution.

![](/files/xQURXhQCI8S4iN1gifzW)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.monokot.io/scripts/programming-examples/how-to-opc-ua-method.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
