# GatewayHook custom functions

**URL:** <https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997>\
**Category:** Module Development\
**Created:** [January 9, 2024, 7:00pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997 "2024-01-09T19:00:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [January 9, 2024, 7:00pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997/1 "2024-01-09T19:00:49Z")

</div>

How do I go about adding a function like `readTag(String tag)` to the Gateway Hook and then use that function elsewhere in my module?

So far I tried adding the gateway scope as a dependency to the client scope, then import the GatewayHook into my component, which is all fine. However when I enter this line under my component's class:

```auto
private GatewayHook gatewayHook = new GatewayHook();

```

Ignition starts throwing errors:

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

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 9, 2024, 7:02pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997/2 "2024-01-09T19:02:33Z")

</div>

You need to be looking at how module RPC works in the scripting example: [ignition-sdk-examples/scripting-function at master · inductiveautomation/ignition-sdk-examples · GitHub](https://github.com/inductiveautomation/ignition-sdk-examples/tree/master/scripting-function)

Your client and gateway code and classes are not only running in entirely different scopes, but in entirely different JVM instances.

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [January 9, 2024, 7:18pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997/3 "2024-01-09T19:18:04Z")

</div>

Thanks. I will have a look at that.

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [January 9, 2024, 8:16pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997/4 "2024-01-09T20:16:22Z")

</div>

For the `scripting-function` example, why are the `MathBlackBox` & `AbstractScriptModule` in the common scope?  
Could I put those directly under the gateway scope in my project?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 9, 2024, 11:10pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997/5 "2024-01-09T23:10:45Z")

</div>

They're in common scope because the interface (and the abstract class; the example predates default methods in interfaces) are _implemented_ on both sides; the client side implements via RPC, while the gateway side just implements directly.

 ![Screenshot 2024-01-09 at 3.11.02 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/0/10f7c555c69b11d62356bf8032c22ce452a9504c.png)

It's a somewhat contrived example that's trying to prove a point.

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [January 10, 2024, 2:47pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997/6 "2024-01-10T14:47:58Z")

</div>

I think I got it all in place now. The TagHandler interface is in the common scope, TagHandlerImpl() is right next to GatewayHook.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/2/e25dbaff6a91b7504b7558e2a495ea7c73b1dc91.png)

This is in the GatewayHook:

```auto
@Override
    public Object getRPCHandler(ClientReqSession session, String projectName) {
        return new TagHandlerImpl();
    }

```

This is in my component on the client side:

```auto
private final TagHandler rpc = ModuleRPCFactory.create(
            "com.inductiveautomation.ignition.lvcontrol.lvcontrol-components",
            TagHandler.class);

```

And this is the test I'm trying to run:

```auto
String str = rpc.test(jobColor);
        System.out.println(str);

```

But I'm getting the following error:

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 10, 2024, 4:43pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997/7 "2024-01-10T16:43:03Z")

</div>

Is your module actually loading correctly on the gateway?

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [January 10, 2024, 4:55pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997/8 "2024-01-10T16:55:53Z")

</div>

I think so. I was initially using the GatewayHook from the "managed-tag-provider" example in my module and it loaded correctly. It created and removed tags and loaded them with random values.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 10, 2024, 4:57pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997/9 "2024-01-10T16:57:19Z")

</div>

Check the module status page on the gateway. That error suggests it's not, _or_ you've got a mismatch in your module IDs somewhere.

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [January 10, 2024, 5:02pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997/10 "2024-01-10T17:02:40Z")

</div>

These are the warnings from the last time I ran Ignition. There are no errors.

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

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [January 10, 2024, 7:09pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-custom-functions/83997/11 "2024-01-10T19:09:25Z")

</div>

Got it to work now. There was a mismatch in the moduleID
