# Calling the system.util.sendMessage function from a Module?

**URL:** <https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063>\
**Category:** 3rd Party Modules\
**Created:** [August 24, 2016, 8:22pm UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063 "2016-08-24T20:22:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelMoran](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MichaelMoran](https://forum.inductiveautomation.com/u/MichaelMoran)\
**Post date:** [August 24, 2016, 8:22pm UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063/1 "2016-08-24T20:22:48Z")

</div>

Is it possible to call the system.util.sendMessage function from an Ignition Module?

---

<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:** [August 24, 2016, 8:59pm UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063/2 "2016-08-24T20:59:21Z")

</div>

Not directly, but you could access the same API from your module that the system.util.sendMessage() functions use to send a message.

Are you trying to send from gateway or client scope?

---

<div class="post-metadata">

**Author:** ![MichaelMoran](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MichaelMoran](https://forum.inductiveautomation.com/u/MichaelMoran)\
**Post date:** [August 26, 2016, 5:44pm UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063/3 "2016-08-26T17:44:42Z")

</div>

Thanks Kevin for the valuable information.  
I’ll try and find the API functions that I need.

Actually I’m trying to use the sendMessage function to send messages to another gateway Module.  
Not sure if this is possible? So I would also need a listener in my Module.

To answer your question I’m trying to send from gateway scope.

---

<div class="post-metadata">

**Author:** ![mgross](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mgross/32/3311_2.png) [@mgross](https://forum.inductiveautomation.com/u/mgross)\
**Post date:** [August 29, 2016, 2:35pm UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063/4 "2016-08-29T14:35:31Z")

</div>

What you will have to do is dispatch the message using MessageDispatchManager, and then you need to set up a message handler in a project that can call a script function in your module (example shown below).

Send code (Java):

```auto
MessageDispatchManager mdm = gatewayContext.getMessageDispatchManager();

PyDictionary payload = new PyDictionary(new PyObject[] {
        new PyString("Source"), new PyString("Gateway"),
        new PyString("Message"), new PyString("testMessage")
});

// Limit to Gateway scope
Properties filterParams = new Properties();
filterParams.setProperty(MessageDispatchManager.KEY_SCOPE, MessageDispatchManager.SCOPE_GATEWAY_ONLY);

// You must specify a project, as message handlers are configured in projects. 
mdm.dispatch("MyProject",
	"MyMessageHandler",
    payload,
    filterParams);
```

Jython Message handler in a project, which must be named “MyMessageHandler”:

```auto
def handleMessage(payload):
	mymodule.myFunction(payload)
```

---

<div class="post-metadata">

**Author:** ![MichaelMoran](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MichaelMoran](https://forum.inductiveautomation.com/u/MichaelMoran)\
**Post date:** [August 30, 2016, 8:16pm UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063/5 "2016-08-30T20:16:48Z")

</div>

Brilliant!  
That worked.  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![michael.palmer](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@michael.palmer](https://forum.inductiveautomation.com/u/michael.palmer)\
**Post date:** [May 19, 2017, 5:03pm UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063/6 "2017-05-19T17:03:10Z")

</div>

I have a message setup this way, and it has been working for several days. Today I was looking at the logs and discovered that it is throwing an error. I’m not quite sure what this error is telling me since the popup message is actually working.

INFO | jvm 1 | 2017/05/19 09:52:49 | E [c.i.i.c.s.m.MessageDispatchManager] [16:52:49]: Gateway script MessageHandlerException, project ‘zzPowertrain\_Battery’ , message handler ‘GenericMessage’  
INFO | jvm 1 | 2017/05/19 09:52:49 | com.inductiveautomation.ignition.common.script.message.MessageHandlerException: The message handler “GenericMessage” could not be found! Check your event script message handlers.  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.common.script.message.MessageHandlerManager.processMessage(MessageHandlerManager.java:168)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.common.script.ScriptConfig.invokeGWMessageHandler(ScriptConfig.java:191)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.gateway.project.ProjectLifecycle.dispatchScriptMessage(ProjectLifecycle.java:431)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.gateway.project.ProjectManagerImpl.invokeGWMessageHandler(ProjectManagerImpl.java:2066)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.gateway.clientcomm.scriptmsg.MessageDispatchManagerImpl.doGatewayNotification(MessageDispatchManagerImpl.java:304)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.gateway.clientcomm.scriptmsg.MessageDispatchManagerImpl.dispatchLocal(MessageDispatchManagerImpl.java:158)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.gateway.clientcomm.scriptmsg.MessageDispatchManagerImpl.dispatch(MessageDispatchManagerImpl.java:98)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.gateway.script.GatewaySystemUtilities.sendMessageInternal(GatewaySystemUtilities.java:147)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.sendMessage(SystemUtilities.java:675)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at java.lang.reflect.Method.invoke(Unknown Source)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at org.python.core.PyReflectedFunction. **call** (PyReflectedFunction.java:186)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. **call** (ScriptManager.java:438)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at org.python.core.PyObject. **call** (PyObject.java:320)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at org.python.pycode._pyx9690.valueChanged$1(tagevent:valueChanged:22)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at org.python.pycode.pyx9690.call\_function(tagevent:valueChanged)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at org.python.core.PyTableCode.call(PyTableCode.java:165)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at org.python.core.PyBaseCode.call(PyBaseCode.java:301)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at org.python.core.PyFunction.function\_\_\_call_(PyFunction.java:376)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at org.python.core.PyFunction. **call** (PyFunction.java:371)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at org.python.core.PyFunction. **call** (PyFunction.java:361)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at org.python.core.PyFunction. **call** (PyFunction.java:356)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:663)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$FunctionInvokerImpl.run(TagScriptManager.java:414)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.common.sqltags.scripts.AbstractTagScript.invoke(AbstractTagScript.java:34)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$Task.invoke(TagScriptManager.java:353)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$TagScriptDispatcher.run(TagScriptManager.java:318)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at com.inductiveautomation.ignition.common.execution.impl.BasicExecutionEngine$ThrowableCatchingRunnable.run(BasicExecutionEngine.java:546)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at java.util.concurrent.FutureTask.run(Unknown Source)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)  
INFO | jvm 1 | 2017/05/19 09:52:49 | at java.lang.Thread.run(Unknown Source)

---

<div class="post-metadata">

**Author:** ![michael.palmer](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@michael.palmer](https://forum.inductiveautomation.com/u/michael.palmer)\
**Post date:** [May 25, 2017, 12:07am UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063/7 "2017-05-25T00:07:20Z")

</div>

Any ideas from anyone? Still have a working popup message and still an error showing in the log file. Strange.

Update:  
Actually I just noticed that this thread is about calling this function from a third party module, but in my case it is erroring within Ignition itself (no third part module).

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 25, 2017, 11:21am UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063/8 "2017-05-25T11:21:27Z")

</div>

Check your calls to sendMessage(). You need to limit to client scope if you haven’t defined a matching message handler in the _gateway_ event scripts, too.

---

<div class="post-metadata">

**Author:** ![michael.palmer](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@michael.palmer](https://forum.inductiveautomation.com/u/michael.palmer)\
**Post date:** [May 25, 2017, 4:02pm UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063/9 "2017-05-25T16:02:08Z")

</div>

Thank you very much. I guess I did not read the documentation closely enough. The default type is “CG”. I just needed to add the scope=“C” to my sendMessage() command and the error in the logger is no longer appearing.
