system.util.sendMessage() perspective scripting

I have a script that calls system.util.sendMessage(). When scope is not provided (default: GCS) I get a return value of:[type=Gateway,project=myProject,messageHandler=test,filterParams={userRoles=, userZones=},isRequest=no,sendStatus=SENT] as expected

However, the message handler in the Gateway Events or Session Events is not triggered. Also, the gateway message handler has a last executed status of ‘Never’ on the Gateway home page under Status>Systems>Gateway Scripts.

Additionally, when scoping the message to ‘S’ I do not get a return value (e.g. system.util.sendMessage() = []).

I can confirm that the project name and the message handler identifier are correct. There are also no errors in the status logs as far as I can see.

Is there anything you can advise that I have probably missed, or is this a bug?

Tested on 8.0.16 & 8.1.0RC1

Could you provide the snippet of code which actually invokes the sendMessage call? Could you also provide a screenshot of the Session Event Message Handler for the myProject project with a handler name of “test”?

Hi @cmallonee

As requested, code snippet:

ret = system.util.sendMessage(project='myProject',messageHandler='test')
system.perspective.print(ret)

Screenshot:

Thank you for your help, I’m still relatively new to the Ignition world, so I’m not sure if I’ve missed something obvious.

I like to play a game called Good News/Bad News:

Good News:
This is working for me, with one small caveat - Sessions which “hear” the broadcast are not reporting as having heard the broadcast (which is why you’re getting an empty array).

Bad News:

  1. You SHOULD see an error in your Gateway logs because you may not use system.perspective.print() in a Session Message Handler as you have it configured. That function requires a page context behind-the-scenes (it needs to know where it’s printing to) but that function is being invoked on the Gateway - which has no pages. You could pass a pageId as part of the payload of the system.util.sendMessage() call, or you could switch to using system.util.getLogger('MYLOGGER').info('message passed'))
  2. Designers don’t truly count as open sessions for the purposes of this function. Essentially, Designers don’t listen for messageHandlers. If you were to open a true Session to a Page/View which contains a component with “test2” configured as a Message Handler and you print some sort of receipt statement, then you’ll see that the message is coming through.
1 Like

@cmallonee thank you for pointing me in the right direction.

This was the line that completed the puzzle in my head. I will also keep in mind the requirements for system.perspective.print().

For the other newbies like myself, and building on what has already been said, if you are passing the message on via system.perspective.sendMessage(), scope is also important unless passing the appropriate pageId. (Please correct me if I’m wrong)

So, scope in this situation is a little tricky, but you have options. You could either supply a scope of 'session" and allow the “broadcast” to be heard by all Pages/Views in all Sessions (because you haven’t filtered this in any way at this point), or you could specify a scope of “page”. If you specify a scope of “page”, however, you MUST supply a sessionId argument as well, which means that you need to already know the session you want to target (potentially passed as part of the payload), or you need to supply logic to locate valid sessions which meet some sort of logical condition using system.perspective.getSessionInfo(). So scope is important, even if you supply a pageId - supplying that argument does not mean that we will locate an appropriate Page from available Sessions.