# Calling OpcUa Server Methods

**URL:** <https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625>\
**Category:** Ignition\
**Created:** [May 12, 2021, 12:03pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625 "2021-05-12T12:03:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason.hook](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jason.hook](https://forum.inductiveautomation.com/u/jason.hook)\
**Post date:** [May 12, 2021, 12:03pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/1 "2021-05-12T12:03:52Z")

</div>

Hi,

I’m new to Ignition. I’d like to create a button on my dashboard to call a method on my opc server, some thing like system.opcua.callMethod(“Ignition-Hound”, “ns=2;i=111”, “ns=2;i=162”, null);

I have learned a little about the various contexts in which scripts can run but wherever I try and use a script I don’t have access to an opcua package or module. I can use system.opc but not system.opcua

What am I doing wrong?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 12, 2021, 12:35pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/2 "2021-05-12T12:35:27Z")

</div>

`system.opcua.callMethod` has a Gateway scope.

Need a bit more information:

Visoin or Perspective  
What version.  
Any error you’re receiving.  
Pertinent code sample

---

<div class="post-metadata">

**Author:** ![jason.hook](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jason.hook](https://forum.inductiveautomation.com/u/jason.hook)\
**Post date:** [May 12, 2021, 12:54pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/3 "2021-05-12T12:54:40Z")

</div>

Thank you for your reply!

I started using Vision but I think I’m about to switch to Perspective. The version of Ignition is 8.1.4.

The code example would be:  
Add a button in the ActionPerformed script add:  
system.opcua.callMethod(“Ignition-Hound”, “ns=2;i=111”, “ns=2;i=162”, null);

The error is:  
Traceback (most recent call last):  
File “event:actionPerformed”, line 1, in   
AttributeError: **‘com.inductiveautomation.ignition.common.script.Imm’ object has no attribute 'opcua’**

```
at org.python.core.Py.AttributeError(Py.java:207)
at org.python.core.PyObject.noAttributeError(PyObject.java:1032)
at org.python.core.PyObject. __getattr__ (PyObject.java:1027)
at org.python.pycode._pyx58.f$0(<event:actionPerformed>:1)
at org.python.pycode._pyx58.call_function(<event:actionPerformed>)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:796)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:206)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:297)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
at com.sun.proxy.$Proxy59.actionPerformed(Unknown Source)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.desktop/java.awt.Component.processEvent(Unknown Source)
at java.desktop/java.awt.Container.processEvent(Unknown Source)
at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

```

Ignition v8.1.4 (b2021040109)  
Java: Azul Systems, Inc. 11.0.9

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/8/a8c018783267327a0d14482eaf6f3d2b35d89658.png)

---

<div class="post-metadata">

**Author:** ![jason.hook](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jason.hook](https://forum.inductiveautomation.com/u/jason.hook)\
**Post date:** [May 12, 2021, 12:58pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/4 "2021-05-12T12:58:24Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/2/a292f54e68c4cb86c712274a50b0f756dc8ed210.png)

With an OpcUa client like UaExpert I can call the method and the server handles the method call and returns a result indicating success (or failure).

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 12, 2021, 1:02pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/5 "2021-05-12T13:02:11Z")

</div>

As @lrose mentioned this function is only available in gateway scope, meaning you can’t call it from the actionPerformed of a Vision button.

If you need to make this happen from a client you need to send a message to a message handler on the gateway that will then call it and possibly return the result.

---

<div class="post-metadata">

**Author:** ![jason.hook](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jason.hook](https://forum.inductiveautomation.com/u/jason.hook)\
**Post date:** [May 12, 2021, 2:37pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/6 "2021-05-12T14:37:20Z")

</div>

Thank you both for replying so swiftly. I’ll see what I can work out. Is there a bit of configuration to do on my part for example when I try to script a gateway event I don’t have access to a system.opcua package just system.opc which presumably is the older OPC not opcua?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 12, 2021, 3:08pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/7 "2021-05-12T15:08:10Z")

</div>

It may just not be showing up in the auto complete menu… I think there was a bug regarding that for a variety of functions but I’m not sure what version it was fixed in (or if it has been fixed yet).

You should still be able to call it from gateway scope even if it doesn’t auto complete.

---

<div class="post-metadata">

**Author:** ![jason.hook](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jason.hook](https://forum.inductiveautomation.com/u/jason.hook)\
**Post date:** [May 13, 2021, 9:20am UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/8 "2021-05-13T09:20:37Z")

</div>

I’ve got it working. I think it was a bit harder than it needed to be but I’m grateful for the help I got yesterday. If it would be helpful for anyone else I can document what I did in another reply.

---

<div class="post-metadata">

**Author:** ![mrutten](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrutten](https://forum.inductiveautomation.com/u/mrutten)\
**Post date:** [October 7, 2021, 2:08pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/9 "2021-10-07T14:08:35Z")

</div>

Jason, It would be helpfull to see what you did to get it to work. I have simular issue.

Thanks.

---

<div class="post-metadata">

**Author:** ![jason.hook](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jason.hook](https://forum.inductiveautomation.com/u/jason.hook)\
**Post date:** [October 7, 2021, 3:07pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/11 "2021-10-07T15:07:18Z")

</div>

In your Ignition Designer double click **Gateway Scripts**. In the dialog select **Message**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/3/7355f7e53a4f39416aa2f11fb64eceab9aaa0ec7.png)

Click **+**

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/7/6784a5447153f876c15cacd2f2e46773ff5c132e.png)

Give your Message Handler a name

This code will make a bit more sense when we look at the Button that sends the message

```auto
	logger = system.util.logger("MyLogger")
	logger.info("Hello from the gateway")
	method = payload['method']
	if method == 'start':
		logger.info("89,92")
		system.opcua.callMethod("PressOperatorController", "ns=2;i=89", "ns=2;i=92", [])
	if method == 'stop':
		logger.info("89,91")
		system.opcua.callMethod("PressOperatorController", "ns=2;i=89", "ns=2;i=91", [])
	return True

```

I’m using a Button to call the method. Right click and **Configure Events**

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/d/8d3692ace5cab166cc10dbd7f23b9c4d01211baa.png)

In the OnClick event I use this line

`returnValue = system.util.sendRequest(project='POC2', messageHandler='new-gw-handler', payload={"method": "start"})`

Can explain more if needed but I think the only bit that’s needs explaining now is the system.opcua.callMethod line.

**system.opcua.callMethod(connectionName, objectId, methodId, inputs)**

```auto

* Parameters

String connectionName - The name of the OPC UA connection to the server that the method resides in.

String objectId - The NodeId of the Object Node the Method is a member of.

String methodId - The NodeId of the Method Node to call.

List inputs - A list of input values expected by the method.

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/e/1e703848d432c661654a8525effb29bf4528502d.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/1/a1fcc387295bc6d89580c2ce28118917a70e800d.png)

Is that enough to get you going?

---

<div class="post-metadata">

**Author:** ![mrutten](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrutten](https://forum.inductiveautomation.com/u/mrutten)\
**Post date:** [October 18, 2021, 3:40pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/12 "2021-10-18T15:40:07Z")

</div>

Yes, I will give it a try today. Thank you for the help. I appreciate it.

---

<div class="post-metadata">

**Author:** ![mrutten](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrutten](https://forum.inductiveautomation.com/u/mrutten)\
**Post date:** [October 18, 2021, 10:23pm UTC](https://forum.inductiveautomation.com/t/calling-opcua-server-methods/46625/13 "2021-10-18T22:23:47Z")

</div>

I got it working with your instructions. thank you.
