Get datasource from Gateway configuration page

I am working on a module where another developer has created a configuration page on the Gateway. One of the settings is datasource. I am wondering how I can access the chosen datasource from my client scoped module.

I believe the page is a com.inductiveautomation.ignition.gateway.web.pages.IConfigPage. I don’t see where the specific settings options are created, so I am assuming they are default options? (datasource, Customer Token, Change Password, Password, Skip Header Validation, Enable).

I think you’re getting caught up in the wrong place. Basically, if someone has created a config page, they’re storing those settings somewhere (they’re not “default” settings, though the the actual config page is likely getting created automatically off of someone’s PersistentRecord that they’ve defined).

Here’s what it sounds like you need to do:

  1. Figure out what record is storing those settings.
  2. Figure out how to get that record from your own module in the gateway (likely just by using [tt]GatewayContext.getPersistenceInterface().find(…)[/tt])
  3. Create an RPC system to retrieve the value in the client, from the gateway. This is described in the Programmer’s guide under “Designer to Gateway Communication”.

Going from there, you could also set up a listener for that record on the gateway, and use push notification to let the client know when someone has changed that setting, though I imagine that is probably a bit more than you need. The mechanics for that are described in “Storing data with PersistentRecords” under “Programming for the Gateway”, and under “Gateway to Client Comm”, under “Programming for the Designer”.

Hope this helps,

Ok, I was able to get the client to call the method on the gateway, but I haven’t figured out how to get the datasource from the persistence record.

My datasource is in a ReferenceField in my PersistentRecord, but I can’t figure out how to use find() to get it.

To get the reference:

  1. Get your persistent record.
  2. Call “findReference” on that record with the reference field.

For example, if your persistent record is called “MySettingsRecord”, and you have a field called “Datasource”, you would do something like this:

MySettingsRecord rec = gwContext.getPersistenceInterface().find(MySettingsRecord.META);
DatasourceRecord dsrec = rec.findReference(MySettingsRecord.Datasource);
String dsName = dsrec.getName();

Regards,

Actually, sorry, I don’t think the code I gave you there will work. The helper function “find” directly on the PersistenceInterface doesn’t keep a session open, so looking up the reference won’t work. You’ll need to get a session and operate on that. Try this instead:

PersistenceSession session = gwContext.getPersistenceInterface().getSession();
String dsName;
try{
    MySettingsRecord rec = session.find(MySettingsRecord.META);
    DatasourceRecord dsrec = rec.findReference(MySettingsRecord.Datasource);
    dsName = dsrec.getName();
}finally{
    try {
        session.close();
    } catch (Exception ignore) { }
}