# Unable to get sendMessage to work

**URL:** <https://forum.inductiveautomation.com/t/unable-to-get-sendmessage-to-work/31992>\
**Category:** Ignition\
**Created:** [February 6, 2020, 1:56pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-sendmessage-to-work/31992 "2020-02-06T13:56:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 6, 2020, 1:56pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-sendmessage-to-work/31992/1 "2020-02-06T13:56:13Z")

</div>

Not sure what I’m missing here, but my script does not work. This is my test script.

```auto
project = "myProject"
messageHandler = "upsStatus"
scope="C"
message = "test message!"
payload = {"message":message}
hostName = "devPi-ip-100"
try:
	system.util.sendMessage(project,messageHandler,payload,scope,hostName)
except:
	print "send message failed"

```

client message handler

```auto
def handleMessage(payload):
	message = payload["message"]
	system.gui.warningBox(message)

```

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 6, 2020, 2:19pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-sendmessage-to-work/31992/2 "2020-02-06T14:19:57Z")

</div>

All I can say is make sure the project, messagehandler, and host names are all correct.

If you do a try: except: and print the error, or just get rid of the try/except so the error bubbles up. Does any error the say?

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [February 6, 2020, 2:31pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-sendmessage-to-work/31992/3 "2020-02-06T14:31:08Z")

</div>

Also make sure the message Handler on the client is named exactly the same as what you are passing.  
It is case sensitive.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 6, 2020, 2:33pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-sendmessage-to-work/31992/4 "2020-02-06T14:33:46Z")

</div>

The sendMessage script does not error out, it completes successfully. The message just never makes it to the client. I tried using the diagnostics window and putting the client message handler in debug mode. when I send the message nothing shows up there. I’ve checked all the names a hundred times, and tried it without the hostname. no matter what it doesn’t work.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [February 6, 2020, 2:35pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-sendmessage-to-work/31992/5 "2020-02-06T14:35:59Z")

</div>

I just checked one of ours and I notice we are explicitly setting the parameters in the sendMessage call.

```auto
app = "myProject"
msgHandler = "upsStatus"
scope="C"
msg = "test message!"
content = {"message":message}
host = "devPi-ip-100"
try:
	system.util.sendMessage(project=app,messageHandler=msgHandler,payload=content,scope="C",hostName=host)
except:
	print "send message failed"

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 6, 2020, 2:39pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-sendmessage-to-work/31992/6 "2020-02-06T14:39:18Z")

</div>

That did the trick, I didn’t notice the explicit definition in the call. Much appreciated!

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 6, 2020, 3:09pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-sendmessage-to-work/31992/7 "2020-02-06T15:09:46Z")

</div>

This has to do with how python (and jython) are interpreting the arguments you are sending. Since you weren’t sending the arguments as `kwargs` originally, they were essentially being interpreted based on their position, so `scope` happened to fall into the correct position because it is the first “optional” argument, but `hostname` would have been interpreted as `clientSessionId`, as that is the next optional argument.

As you’ve already found, supplying the arguments with their associated keyword clears everything up as the arguments are now explicitly defined for the function.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 6, 2020, 3:32pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-sendmessage-to-work/31992/8 "2020-02-06T15:32:16Z")

</div>

@cmallonee Can you use wildcards in the hostName arg?

```auto
hostName = 'cush-ip*'

```

**EDIT**  
Doesn’t seem so, looks like a for loop and a list is the way to handle this

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [February 6, 2020, 4:34pm UTC](https://forum.inductiveautomation.com/t/unable-to-get-sendmessage-to-work/31992/9 "2020-02-06T16:34:29Z")

</div>

You could always pull the node list and then filter and send.

```auto
nodes = system.util.getSessionInfo()
listnumber = len(nodes)
for x in range(listnumber):
	if 'cush-ip' in nodes[x][2]:
		system.util.sendMessage()

```
