# Executing a custom script as a gateway script with hidden parameters

**URL:** <https://forum.inductiveautomation.com/t/executing-a-custom-script-as-a-gateway-script-with-hidden-parameters/50315>\
**Category:** Module Development\
**Created:** [August 26, 2021, 9:02am UTC](https://forum.inductiveautomation.com/t/executing-a-custom-script-as-a-gateway-script-with-hidden-parameters/50315 "2021-08-26T09:02:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlunapinel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mlunapinel/32/19719_2.png) [@mlunapinel](https://forum.inductiveautomation.com/u/mlunapinel)\
**Post date:** [August 26, 2021, 9:02am UTC](https://forum.inductiveautomation.com/t/executing-a-custom-script-as-a-gateway-script-with-hidden-parameters/50315/1 "2021-08-26T09:02:44Z")

</div>

Hello all!

First of all, my apologies for the cryptic title, it’s hard to explain.

I have a scripting funcion that uses two parameters, for example:

```auto
system.mymodule.myfunction(Date date1, Date date2)

```

This funcion uses a project resource to perform some task. When I execute it on the script console it works great because when I create the script module I pass the project from where I’m executing as a parameter (that way the module can gather the resource using the projectName), like this:

```auto
//IN DESIGNER HOOK
public void initializeScriptManager(ScriptManager manager) {
        super.initializeScriptManager(manager);

        manager.addScriptModule(
                "system.mymodule",
                new DesignerScriptModule(DesignerHook.getDesignerContext().getProjectName()),
                new PropertiesFileDocProvider()
        );
    }

```

The problem is that when I add the script module in the gateway, I obviously cannot add a project name since we can have multiple projects in a gw.

```auto
//IN GATEWAYHOOK
public void initializeScriptManager(ScriptManager manager) {

        super.initializeScriptManager(manager);
        manager.addScriptModule(
                "system.performanceRatio",
                new GatewayScriptModule(),
                new PropertiesFileDocProvider());
    }

```

Is there any way to have the gateway know which project set the script up? Of course I can always add another parameter to the function and let the user write the project name but that seems less elegant.

Thanks in advance!

---

<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:** [August 26, 2021, 10:30am UTC](https://forum.inductiveautomation.com/t/executing-a-custom-script-as-a-gateway-script-with-hidden-parameters/50315/2 "2021-08-26T10:30:44Z")

</div>

That hook method will be called for each scope in the gateway. It is ugly, but the project will already be set for `system.util.getProjectName`. You can use the given script manager to execute a one-liner that assigns that to a local variable, and extract that local variable’s value for your use.

There may be a less hacky way to do this.

---

<div class="post-metadata">

**Author:** ![mlunapinel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mlunapinel/32/19719_2.png) [@mlunapinel](https://forum.inductiveautomation.com/u/mlunapinel)\
**Post date:** [August 26, 2021, 11:36am UTC](https://forum.inductiveautomation.com/t/executing-a-custom-script-as-a-gateway-script-with-hidden-parameters/50315/3 "2021-08-26T11:36:54Z")

</div>

As always, thanks for your answer @pturmel, that is a really clever solution. Do you happen to know how to invoke the funcion `system.util.getProjectName` from the sdk?

About a less hacky way, I just found the [ProjectScriptModule](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.8/com/inductiveautomation/ignition/common/script/ProjectScriptModule.html) class which sounds perfect for my use case but there is no info other than “A ScriptModule representing a project resource”. If anyone has any info on how to use this it would be greatly appreciatted 🙂 !

---

<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:** [August 26, 2021, 3:13pm UTC](https://forum.inductiveautomation.com/t/executing-a-custom-script-as-a-gateway-script-with-hidden-parameters/50315/4 "2021-08-26T15:13:29Z")

</div>

In _most_ circumstances, we’ll automatically set various values on the `com.inductiveautomation.ignition.common.script.ScriptContext` class before actually invoking a script. You can use the `defaultProject()` method on that class.

---

<div class="post-metadata">

**Author:** ![mlunapinel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mlunapinel/32/19719_2.png) [@mlunapinel](https://forum.inductiveautomation.com/u/mlunapinel)\
**Post date:** [August 27, 2021, 7:39am UTC](https://forum.inductiveautomation.com/t/executing-a-custom-script-as-a-gateway-script-with-hidden-parameters/50315/5 "2021-08-27T07:39:52Z")

</div>

Works like a charm, thank you both!
