Message handlers between two projects

Hello all,

I’m new in Ignition and i want to refresh a table in a project called “A” by a message handler sent by project “B”.
i tried this :
system.util.sendMessage(project=“A”,messageHandler = “Refresh_Table”)
and in my table component in project “A” i have the message handler called “Refresh_Table”

However i have this error message:

Gateway script MessageHandlerException, project ‘Lampes’, message handler ‘Refresh_Table’: com.inductiveautomation.ignition.common.script.message.MessageHandlerException: The message handler “Refresh_Table” could not be found! Check your event script message handlers.

what did i miss ?

Thanks in advance !

You’ll have to add a message broker between the projects first.
Start here: system.util.sendMessage - Ignition User Manual 8.1 - Ignition Documentation
Ignore the above. You’re using system.util.sendMessage()

In project A you will setup your receiver and from there you can call system.perspective.sendMessage() to call Refresh_Table

The receiving message is setup in the session events:

Session events Message info:
https://docs.inductiveautomation.com/display/DOC81/Perspective+Session+Event+Scripts#PerspectiveSessionEventScripts-Message

Hello @Corentin.appart.

As I can see, you are using system.util.sendMessage function, wich only works if the Message Handler is configured either on Client / Gateway / Session Event Scripts.

A Message Handler defined in a perspective component must be called with the function system.perspective.sendMessage. This functions only works is the call and the handler are in the same project.

So, in your case, you must move the message handler defined in the component to a message handler defined in Session event scripts.

Thank a lot for your support, i really appreciate it!

so, In my project A (Where I want to refresh my table ) I have to create a Session Message Handlers (“Refresh_TableSession”) where i’ll use system.perspective.sendMessage(“Refresh_Table”).
In my table (in project A) i have to configure script and add the message Handlers “Refresh_Table” with my script.
and in project B i only need to use system.util.sendMessage(project=“A”, messageHandler= “Refresh_TableSession”)

Is it right ?

Thanks for your support

2 Likes

Yes that sounds right @Corentin.appart. Good luck!

1 Like

One additional thing to note is that you should probably set the “Scope” argument for system.util.sendMessage(). If you don’t then it will send to all the scopes which will throw that MessageHandlerException you were seeing when it tries to find a message handler in a scope it doesn’t exist in. From what I can tell in your use case, you’ll want to set it to “S” for session so that it only sends it to session message handlers.

2 Likes

Thanks for your reply,

it looks like it can find the MessageHandler now.
However, my script is not running on my table component the table is not refreshing, and i have a warning with the following comments : " no perspective page attached to this thread "
should i need to provide a pageID or something like that somewhere ?

Seems like a bug to me but not certain. The perspective module doesn’t seem accessible from the session event scripts (ctrl+space not working for system.perspective ).

It depends on where you’re calling the script from.

Could you please provide:

  • the exact code you’re executing and clearly define which area that code is in
  • your current version

The error you’re seeing is typically encountered when a .perspective package function is invoked in an area of the application which does not have a Perspective context. I would expect to see that error if you’re invoking system.perspective package functions in a Gateway context outside of a Perspective area.

OR

You might not be supplying the correct scope; if you don’t specify “session”, then the function uses the “page” scope, which requires you also supply the pageId and which would then require access to the Perspective page thread.

Thanks for your reply!

i’m in 8.0.16
In project B :
I have a button with On click event with the following script :

Then in Project A :
in Project>Session Event :

and on script event on the table i want to refresh :

And the log when i try to click on the button.

I think that scope = “S” is not really what i want because the second project will not run on the same session (second project open by an other user…)

Hope it’s clear enough for you and i would like to thank you for your support ! :slight_smile:

I think i should not use a session event to create my message handler

No, you do want to use the “S” for Session scope. Your issue is that your Projects > Session Event call of sendMessage does not provide a scope. Change the Project > Session Event to be this:

system.perspective.sendMessage("Refresh_Table", scope='session')

If you don’t specify the scope as being “session”, then the function defaults to the “page” scope, which requires that you either invoke the function from a Perspective Page, or that you supply a pageId argument.

Ok thanks for your support !
it works now !
have a good day :slight_smile:

1 Like