Providing PersistentRecord data to common class

I have a relatively simple settings page that is taking in a few config points needed in my common scripting.

I have been struggling to get some persistent record data from the gateway module into the common module for said scripting.

I have tried everything from parameterizing the base class in the common module, to setting public variables on the script module itself before I add it to the script manager. Or figuring out a way to just access the localdb directly in the common scope.

Is there a typical way to access persistent record data in the common scope? I am struggling to find any info that isn’t gateway-scope specific.

Thanks,
Keith G.

You can’t. You will have to use other data types (in common scope) to represent the content of your persistent record that don’t rely on or access that record class. Then establish an RPC interface that can populate that data common data type. In gateway scope, implement the RPC interface with direct access to the persistent record. In Vision Client and Designer scopes, implement the RPC interface with a call to the gateway’s RPC implementation.

The common scope cannot access any gateway resources directly. All such must be indirect, with implementations per-scope.

Originally I was on that path, but kept having issues trying to load my settings record into the gateway script module that extends my common-scoped script module.

public class GatewayScriptModule extends AbstractScriptModule {

    private GatewayContext context;
    MySettingsRecord settingsRecord = context.getLocalPersistenceInterface().find(MySettingsRecord, 0L);

    @Override
    protected String getSettingValue() {
        return settingsRecord.getMySetting();
    }

I get an NPE where my hook tries to load the module

 private final GatewayScriptModule scriptModule = new GatewayScriptModule();

That points back to the line where I get the persistenceInterface

Of course you get an NPE, you haven’t assigned context at that point and you immediately try to use it.

Derp…

I adjusted the script to use a function that creates the settings record when needed, instead of when the module is instantiated and then after I create it I provide the module with the context from my hook and that seems to work great!

public class GatewayScriptModule extends AbstractScriptModule {
    
    public GatewayContext context;

    private MySettingsRecord getSettingsRecord()
    {
        MySettingsRecord settingsRecord = context.getLocalPersistenceInterface().find(MySettingsRecord, 0L);
        return settingsRecord;
    }

    @Override
    protected String getSettingValue() {
        MySettingsRecord settingsRecord = getSettingsRecord();
        return settingsRecord.getMySetting();
    }

and in my setup() method on the hook I put this after I create my settingsRecord if needed

scriptModule.context = this.context;

However I am curious is this the proper way to give that module context? I know in the hook I get it from the startup functions, but is there a direct way to get it in the gateway script module?

What’s wrong with your GatewayScriptModule having a constructor that accepts a GatewayContext?

1 Like

Nothing at all, just switched to that.

Just wasn’t sure if that was the right path or not!