# Message handlers between two projects

**URL:** <https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 29, 2020, 1:52pm UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834 "2020-12-29T13:52:38Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Corentin.appart](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Corentin.appart](https://forum.inductiveautomation.com/u/Corentin.appart)\
**Post date:** [December 29, 2020, 1:52pm UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/1 "2020-12-29T13:52:38Z")

</div>

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”

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

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 !

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [December 29, 2020, 2:49pm UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/2 "2020-12-29T14:49:57Z")

</div>

~~You’ll have to add a message broker between the projects first.~~  
~~Start here: [system.util.sendMessage - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.util.sendMessage)~~  
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:

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

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

---

<div class="post-metadata">

**Author:** ![avg](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@avg](https://forum.inductiveautomation.com/u/avg)\
**Post date:** [December 29, 2020, 3:02pm UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/4 "2020-12-29T15:02:25Z")

</div>

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.

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

---

<div class="post-metadata">

**Author:** ![Corentin.appart](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Corentin.appart](https://forum.inductiveautomation.com/u/Corentin.appart)\
**Post date:** [December 29, 2020, 3:33pm UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/5 "2020-12-29T15:33:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [December 29, 2020, 3:51pm UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/6 "2020-12-29T15:51:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [December 29, 2020, 4:33pm UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/7 "2020-12-29T16:33:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Corentin.appart](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Corentin.appart](https://forum.inductiveautomation.com/u/Corentin.appart)\
**Post date:** [December 30, 2020, 8:12am UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/8 "2020-12-30T08:12:04Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [December 30, 2020, 1:36pm UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/9 "2020-12-30T13:36:19Z")

</div>

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 ).

---

<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:** [December 30, 2020, 5:03pm UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/10 "2020-12-30T17:03:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Corentin.appart](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Corentin.appart](https://forum.inductiveautomation.com/u/Corentin.appart)\
**Post date:** [December 31, 2020, 10:32am UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/12 "2020-12-31T10:32:15Z")

</div>

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 :

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

Then in Project A :  
in Project\>Session Event :

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

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/0/909d05a0b34b27101a791668f0ce6f99bd6d957c.png)

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 ! 🙂

---

<div class="post-metadata">

**Author:** ![Corentin.appart](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Corentin.appart](https://forum.inductiveautomation.com/u/Corentin.appart)\
**Post date:** [December 31, 2020, 11:54am UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/13 "2020-12-31T11:54:58Z")

</div>

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

---

<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:** [December 31, 2020, 4:05pm UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/14 "2020-12-31T16:05:46Z")

</div>

> [@Corentin.appart](#):
>
> 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…)

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Corentin.appart](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Corentin.appart](https://forum.inductiveautomation.com/u/Corentin.appart)\
**Post date:** [January 4, 2021, 7:36am UTC](https://forum.inductiveautomation.com/t/message-handlers-between-two-projects/41834/15 "2021-01-04T07:36:23Z")

</div>

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