# Programmatically Add Script

**URL:** <https://forum.inductiveautomation.com/t/programmatically-add-script/112165>\
**Category:** Module Development\
**Tags:** ignition81\
**Created:** [November 13, 2025, 5:24pm UTC](https://forum.inductiveautomation.com/t/programmatically-add-script/112165 "2025-11-13T17:24:39Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![Porter\_Ellis](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Porter\_Ellis](https://forum.inductiveautomation.com/u/Porter_Ellis)\
**Post date:** [November 14, 2025, 7:22pm UTC](https://forum.inductiveautomation.com/t/programmatically-add-script/112165/21 "2025-11-14T19:22:03Z")

</div>

getInstance() is deprecated. Is there a supported method? Also, I am doing this in the startup method. Should I be doing this somewhere else?

---

<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:** [November 14, 2025, 8:14pm UTC](https://forum.inductiveautomation.com/t/programmatically-add-script/112165/22 "2025-11-14T20:14:56Z")

</div>

It's been deprecated since (at least) 2011. As the person who would be in charge of ever dealing with removing it...it's not ever going to get removed.

There's no way to get the private `app` field from the `ClientContextImpl` you get delivered on startup:

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

---

<div class="post-metadata">

**Author:** ![Porter\_Ellis](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Porter\_Ellis](https://forum.inductiveautomation.com/u/Porter_Ellis)\
**Post date:** [November 14, 2025, 9:06pm UTC](https://forum.inductiveautomation.com/t/programmatically-add-script/112165/23 "2025-11-14T21:06:36Z")

</div>

```python
public void startup(ClientContext context, LicenseState activationState) throws Exception {
        super.startup(context, activationState);
        ClientHook.context = context;
        visionDesktop = new VisionDesktop(context) {
            @Override
            protected VisionClientContext initContext(ClientContext clientContext) {
                return this.getAdapterContext();
            }
        };
        DesktopListener desktopListener = new DesktopListener() {...

```

This is what I have. I initially tried FPMIApp.getInstance().getAdapterContext() but got a static reference in a non-static context issue. This code (using `this.getAdapterContext()`) throws the following:

`Cannot invoke "com.inductiveautomation.ignition.client.model.ClientContext.getRootPaneContainer()" because "context" is null`

And if I use FPMIApp.getInstance().getAdapterContext() to get the VisionClientContext, then get the VisionDesktop from that, I get the following error:

`java.lang.NullPointerException: Cannot invoke "com.inductiveautomation.factorypmi.application.FPMIApp.getAdapterContext()" because the return value of "com.inductiveautomation.factorypmi.application.FPMIApp.getInstance()" is null`

This is even after an earlier usage of the ‘context’ field in a scriptModule initialization. What am I doing wrong?

---

<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:** [November 14, 2025, 9:51pm UTC](https://forum.inductiveautomation.com/t/programmatically-add-script/112165/24 "2025-11-14T21:51:39Z")

</div>

You are trying to create your own VisionDesktop. That can't be right.

---

<div class="post-metadata">

**Author:** ![Porter\_Ellis](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Porter\_Ellis](https://forum.inductiveautomation.com/u/Porter_Ellis)\
**Post date:** [November 14, 2025, 9:54pm UTC](https://forum.inductiveautomation.com/t/programmatically-add-script/112165/25 "2025-11-14T21:54:56Z")

</div>

But even when I don’t try to create my own and retrieve it via `getAdapterContext()`, my context object is null. Here is that code:

```python
super.startup(context, activationState);
        ClientHook.context = context;
        FPMIApp app = FPMIApp.getInstance();
        VisionClientContext vcc = app.getAdapterContext();
        VisionDesktop vd = vcc.getPrimaryDesktop();
        DesktopListener desktopListener = new DesktopListener() {

```

---

<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:** [November 14, 2025, 10:34pm UTC](https://forum.inductiveautomation.com/t/programmatically-add-script/112165/26 "2025-11-14T22:34:09Z")

</div>

> [@Porter\_Ellis](#):
>
> ` VisionClientContext vcc = app.getAdapterContext();`

_This_ line is returning null?

I don't see how that's possible - that `context` field in `VisionDesktop` is final and assigned in the constructor. I could see a possibility of `getInstance()` returning null, because we're way in the weeds of startup timing stuff and this is a lot less defined than gateway startup ordering, but I can't see how `getAdapterContext` could return null.

---

<div class="post-metadata">

**Author:** ![Porter\_Ellis](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Porter\_Ellis](https://forum.inductiveautomation.com/u/Porter_Ellis)\
**Post date:** [November 14, 2025, 10:35pm UTC](https://forum.inductiveautomation.com/t/programmatically-add-script/112165/27 "2025-11-14T22:35:46Z")

</div>

Sorry I wasn’t speaking clearly. `getInstance()`is returning null.

---

<div class="post-metadata">

**Author:** ![Porter\_Ellis](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Porter\_Ellis](https://forum.inductiveautomation.com/u/Porter_Ellis)\
**Post date:** [November 14, 2025, 11:06pm UTC](https://forum.inductiveautomation.com/t/programmatically-add-script/112165/28 "2025-11-14T23:06:26Z")

</div>

I found a solution. I abstracted the creation of the `DesktopListener` to a function that returns it as a `CompleteableFuture`, then called that function from withing `ClientHook.startup()`.

[Previous page](https://forum.inductiveautomation.com/t/programmatically-add-script/112165.md?page=1)
