# Run a gateway script on a remote Gateway

**URL:** <https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179>\
**Category:** Ignition Early Access\
**Created:** [February 12, 2020, 5:27pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179 "2020-02-12T17:27:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![smiano](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@smiano](https://forum.inductiveautomation.com/u/smiano)\
**Post date:** [February 12, 2020, 5:27pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/1 "2020-02-12T17:27:23Z")

</div>

Here is the situation:  
We have 2 gateways. Gateway #1 is hosted in the cloud, Gateway #2 is hosted inside the site network. They have allowed the Gateway-to-Gateway port through the firewall, but none other. The Gateway Network has been established and is communicating.

I want to run a script on the Internal gateway (gateway#2) and pass the results to gateway#1. Also, the function call should be initiated from gateway#1 by some mechanism (doesn’t quite matter at this point).

Is there a standard Ignition mechanism to do this?

Thanks

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [February 12, 2020, 5:38pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/2 "2020-02-12T17:38:38Z")

</div>

You can probably use [https://docs.inductiveautomation.com/display/DOC80/system.util.sendRequest](https://docs.inductiveautomation.com/display/DOC80/system.util.sendRequest)  
or sendMessage

---

<div class="post-metadata">

**Author:** ![smiano](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@smiano](https://forum.inductiveautomation.com/u/smiano)\
**Post date:** [February 12, 2020, 7:08pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/3 "2020-02-12T19:08:10Z")

</div>

Thanks jpark,

Any idea what the configuration will look like on the side receiving the request? Is the messageHandler parameter the Global Function Name or do you have to set up a mechanism on the other side to “catch” the sendRequest?

-Steve

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 12, 2020, 7:12pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/4 "2020-02-12T19:12:34Z")

</div>

You add the handler under the message section of gateway event scripts on the receiving gateway:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/762180746df2be733c4e475f1232f611e1927ae2.png)  
The messageHandler parameter matches the gateway message handler name (“logger” in the example shown).

---

<div class="post-metadata">

**Author:** ![smiano](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@smiano](https://forum.inductiveautomation.com/u/smiano)\
**Post date:** [February 12, 2020, 8:06pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/5 "2020-02-12T20:06:44Z")

</div>

Thanks for the screenshot @witman

Based on the documentation, it looks like I will be able to call the message function from a Client session on Gateway #1. Would you agree?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/8ca30603cc2d7924dc2d27bd6a9864d0ffd16faa.png)

@jpark

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 12, 2020, 8:12pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/6 "2020-02-12T20:12:26Z")

</div>

You could send it from a client, but from your initial description it sounds like you’d want to send it from the gateway, which should also work (from further down the on the documentation page):  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/64134ee77b8f437cbd9dc0d2e059a9da3dd74c93.png)  
The part you highlighted just specifies that there are no special client permissions required to use it from a client.

---

<div class="post-metadata">

**Author:** ![smiano](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@smiano](https://forum.inductiveautomation.com/u/smiano)\
**Post date:** [February 12, 2020, 8:56pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/7 "2020-02-12T20:56:51Z")

</div>

I’ll let you know how it all worked out once I implement.  
Thanks

---

<div class="post-metadata">

**Author:** ![smiano](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@smiano](https://forum.inductiveautomation.com/u/smiano)\
**Post date:** [February 13, 2020, 4:46am UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/8 "2020-02-13T04:46:51Z")

</div>

@witman @jpark  
So I got it to work from Gateway#1 to Gateway#2 in the designer Script Console, however in a runtime client I am getting this error message in the Thread Logs:  
“…MessageHandlerException: User does not have required permissions…”

Any idea what setting needs to happen to appease the Security gods?  
I can dump the full long error message if that will help you figure it out.

---

<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:** [February 13, 2020, 12:09pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/9 "2020-02-13T12:09:52Z")

</div>

> [@smiano](#):
>
> to appease the Security gods

Look in the project properties dialog. There're several security limits that are default for new projects.

---

<div class="post-metadata">

**Author:** ![smiano](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@smiano](https://forum.inductiveautomation.com/u/smiano)\
**Post date:** [February 13, 2020, 7:45pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/10 "2020-02-13T19:45:51Z")

</div>

Thanks for the reply @pturmel.

I set these to all to True for both GW#1 and GW#2 - still no luck

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/1/15bb7e4fb58a43876f8fbd3286d8ed46058a2d06.png)

---

<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:** [February 13, 2020, 7:52pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/11 "2020-02-13T19:52:59Z")

</div>

Actually, a runtime client shouldn’t matter. You should be sending the message only to gateway scope, and the handler should be under the gateway scripts, not the (Vision) client scripts.

---

<div class="post-metadata">

**Author:** ![smiano](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@smiano](https://forum.inductiveautomation.com/u/smiano)\
**Post date:** [February 15, 2020, 5:22pm UTC](https://forum.inductiveautomation.com/t/run-a-gateway-script-on-a-remote-gateway/32179/13 "2020-02-15T17:22:52Z")

</div>

@pturmel @jpark @witman

Got it working. I had left the Security Zone settings as non-default on GW#2, which was blocking the action in the client session.

Here is the final configuration:  
Remote Message Call from GW#1 to GW#2:  
def remoteRequestGetTagsValueForDate(tagsList, dt):  
try:  
requestReturn = system.util.sendRequest(project=‘Sandbox’, messageHandler=‘getTagsValueForDate’, payload={‘tagsList’:tagsList, ‘dt’:dt}, remoteServer=“ignition-ip-172-00-00-01”, timeoutSec=10000)  
return requestReturn  
except:  
return “Error running global function”

Message Handler config on GW#2:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/82ad52c368debdb7beac4d905d84aa1ec18ba57f.png)

Global Script defined on GW#2:  
def getTagsValueForDate(tagsList, dt):
