Why Ignition module automatically update the initial record

Hi everyone,

I create a demo module which will create an initial record at the setup procedure.

But when I want to add new record, I find that the initial record will automatically updated.

For example, the initial record I create is “HomeConnect Hub” at the setup procedure.
But if I add a new record which is “NEW CREATED”, the initial record will be updated to “NEW CREATED”.


So my questions are:
1.Is there a way to avoid updated the initial record?
2.I tried not to create the initial record at first time, but then run into an internal error. Why does that happen?
I think the initial record is necessary but I do not know the reason.

Any PersistentRecords (and thus, tables in the internal DB) required for your module to run should be created in your modules GatewayHook#setup() by calling GatewayContext.getSchemaUpdater().updatePersistentRecords()

What it does after that is attempt to create a ‘singleton’ instance of the Home Connect record, in the maybeCreateHCSettings method. What modifications did you make to this example? The 0L primary key is the important part; it’s always referring to records by the HCSETTINGSRECORD_ID. As the module is written, a default record will be created and any editing on the config page will happen on that single record.

For a slightly different approach - say you want to be able to configure additional devices, you can try the secret-keeper module I just wrote up as a proof of concept.
The GatewayHook ensures the required table exists, but does not create any records.
Meanwhile, the SecretManagerPage uses the Ignition API class RecordActionTable to create the default CRUD interaction around a PersistentRecord implementation - you’ll be able to add new records, update existing ones, etc.

2 Likes

Thanks for your reply sir.
I will have a deep look into the code. :+1: :+1: :+1: