# ReferenceField to TagProvider in PersistentRecord

**URL:** <https://forum.inductiveautomation.com/t/referencefield-to-tagprovider-in-persistentrecord/85536>\
**Category:** Module Development\
**Created:** [February 11, 2024, 8:59pm UTC](https://forum.inductiveautomation.com/t/referencefield-to-tagprovider-in-persistentrecord/85536 "2024-02-11T20:59:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryo\_Kamata](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@Ryo\_Kamata](https://forum.inductiveautomation.com/u/Ryo_Kamata)\
**Post date:** [February 11, 2024, 8:59pm UTC](https://forum.inductiveautomation.com/t/referencefield-to-tagprovider-in-persistentrecord/85536/1 "2024-02-11T20:59:01Z")

</div>

I'm trying to make a config on the gateway to have a tickbox to have a boolean config field per tag provider in a gateway. Essentially I'm trying to create a table with a one-to-one relationship to tag providers and an additional column for configuration.

Following [this post](https://forum.inductiveautomation.com/t/wicket-database-dropdown-editor/40967), right now the PersistentRecord looks like:

```auto
public class TagProvidersConfigRecord extends PersistentRecord {
    ...
    // Reference to tag provider
    public static final LongField TagProviderId = new LongField(META, "TagProviderId", SFieldFlags.SPRIMARY_KEY);
    public static final ReferenceField<TagProviderSettingsRecord> TagProvider = new ReferenceField<>(META,
            TagProviderSettingsRecord.META, "Tag Provider", TagProviderId);
    ...
}

```

I think that's all fine, but I can't seem to find any APIs for getting an Id to reference the tag provider.

The closest thing I've found in the javadocs is the PROVIDER\_ID property on [TagProviderSettingsRecord (inductiveautomation.com)](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.37/com/inductiveautomation/ignition/gateway/tags/api/TagProviderSettingsRecord.html) (hence the type in ReferenceField above). This seems like what I need but I can't find a way to get this from the gateway context? I can get the list of tag providers in the gateway setup with `List<TagProvider> tagProviders = gatewayContext.getTagManager().getTagProviders();` but I can't find a way to get to the record from there.

If there's a better way to do this, please let me know as well.  
Thank you in advance.

---

<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:** [February 12, 2024, 4:22pm UTC](https://forum.inductiveautomation.com/t/referencefield-to-tagprovider-in-persistentrecord/85536/2 "2024-02-12T16:22:14Z")

</div>

I'm not quite sure I understand the question, but `BaseExtensionPointType` (the abstract class at the root of the "extension point" mechanism we use to provide pluggable functionality like alarm journal types, tag provider types, etc) contains this `protected` implementation, to return the 'base' record given a reference field:

```java
    /**
     * Convenience function for looking up the extension point's settings for the given profile. Relies on
     * getSettingsRecordForeignKey() to get the reference field for the settings record.
     */
    protected <T> T findProfileSettingsRecord(GatewayContext context, PersistentRecord profile) {
        if (getSettingsRecordType() == null || getSettingsRecordForeignKey() == null) {
            return null;
        }
        PersistenceSession session = context.getPersistenceInterface().getSession(profile.getDataSet());

        try {
            @SuppressWarnings("rawtypes")
            T result = (T) session.queryOne(
                new SQuery(getSettingsRecordType()).eq(getSettingsRecordForeignKey(), profile));

            return result;
        } finally {
            session.commitAndDetachDataSet();
            session.close();
        }
    }

```

---

<div class="post-metadata">

**Author:** ![Manuel\_Rodriguez](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@Manuel\_Rodriguez](https://forum.inductiveautomation.com/u/Manuel_Rodriguez)\
**Post date:** [April 11, 2025, 3:13pm UTC](https://forum.inductiveautomation.com/t/referencefield-to-tagprovider-in-persistentrecord/85536/3 "2025-04-11T15:13:43Z")

</div>

I have a question regarding PersistentRecord. Currently, we are storing the IDs for TagProvider and HistoryProvider using the following code:

```python
public static final LongField TagProviderId = new LongField(META, "TagProviderId"); 
public static final ReferenceField<TagProviderSettingsRecord> TagProvider = new ReferenceField<TagProviderSettingsRecord>(META, TagProviderSettingsRecord.META, "TagProvider", TagProviderId);

public static final LongField HistoryProviderId = new LongField(META, "HistoryProviderId");
public static final ReferenceField<TagHistoryProviderRecord> HistoryProviderReference = new ReferenceField<>(META, TagHistoryProviderRecord.META, "HistoryProviderReference", HistoryProviderId);

```

Is there a way to retrieve the value or complete record associated with a given `tagProviderId`? In other words, is there a class that allows obtaining the specific record we are looking for without having to load the entire dataset?

---

<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:** [April 11, 2025, 4:18pm UTC](https://forum.inductiveautomation.com/t/referencefield-to-tagprovider-in-persistentrecord/85536/4 "2025-04-11T16:18:29Z")

</div>

[`PersistenceInterface`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.47/com/inductiveautomation/ignition/gateway/localdb/persistence/PersistenceInterface.html) is your entrypoint - I'm pretty sure you just do `find(TagProviderSettingsRecord.META, yourTagProviderIdValue);`.
