Solutions
...
Litmus Production Record Datab...
Interacting with Litmus Produc...

Inserting Production Record Item if not using Litmus Edge Integration via JSON

6min

Note: This feature requires Litmus Production Record Database V 1.4.0.0 or higher.

Use Cases

Litmus Production Record Database allows for several ways to insert data into its tables.

The recommended way when using Litmus Edge, is to make use of the MSSQL Integrations to insert data directly into the table PROREC_Misc_Transactions. As it allows to make use of the integrated store and forward capability, preventing data loss on a connection interruption.

But for cases, where this is not an option, a stored procedure can be called by a program or code snippet to insert data data. Any application which provided the capability to use an ODBC connection can be used like:

  • Python
  • C#
  • .Net
  • Excel
  • Go
  • Java

Method

Execute Stored Procedure PROREC_Misc_WriteIntoTransactionTables using a JSON object as Input.

Input Variables

Variable name

Datatype

Description

Example

@JSONInput

VARCHAR(8000)

A single JSON object which has to always include the keys:

  • deviceid -> comma separated lists consisting of Node Name and optional Level Names
  • registerid -> comma separated lists of Identifier Item Names
  • tagname -> holds the Item name
  • datatype -> comma separated lists of values for the Identifiers provided in @registerid
  • value -> value for the Item specified by @tagname
  • success -> definition if the Item is an Identifier? (1 = No, 0 = Yes)

Or an Array of JSON objects for multiple inserts

[{"deviceid":"EnergyMonitoringDevice_DTDL","registerid":"DT_Instance,Asset","tagname":"Asset","datatype":"EDM_L3_Machine1,123","value":"123","success":true},{"deviceid":"EnergyMonitoringDevice_DTDL","registerid":"DT_Instance,Asset","tagname":"DT_Instance","datatype":"EDM_L3_Machine1,123","value":"EDM_L3_Machine1","success":true},,{"deviceid":"EnergyMonitoringDevice_DTDL,telemetry,power","registerid":"DT_Instance,Asset","tagname":"value","datatype":"EDM_L3_Machine1,123","value":"52.524841352846764","success":false},{"deviceid":"EnergyMonitoringDevice_DTDL,telemetry,power","registerid":"DT_Instance,Asset","tagname":"timestamp","datatype":"EDM_L3_Machine1,123","value":"1694688519848","success":false}]

How to use

To insert a value(s) for Production Record Item(s) via JSON, call the stored procedure PROREC_Misc_WriteIntoTransactionTables using the T-SQL EXEC or EXECUTE keyword and provide the Input variable. Below is an example using T-SQL in SQL Server Management Studio:

EXEC [LE_ProductionRecord].[dbo].[PROREC_Misc_WriteIntoTransactionTables] @JSONInput = N'[{"deviceid":"EnergyMonitoringDevice_DTDL","registerid":"DT_Instance,Asset","tagname":"Asset","datatype":"EDM_L3_Machine1,123","value":"123","success":true},{"deviceid":"EnergyMonitoringDevice_DTDL","registerid":"DT_Instance,Asset","tagname":"DT_Instance","datatype":"EDM_L3_Machine1,123","value":"EDM_L3_Machine1","success":true},,{"deviceid":"EnergyMonitoringDevice_DTDL,telemetry,power","registerid":"DT_Instance,Asset","tagname":"value","datatype":"EDM_L3_Machine1,123","value":"52.524841352846764","success":false},{"deviceid":"EnergyMonitoringDevice_DTDL,telemetry,power","registerid":"DT_Instance,Asset","tagname":"timestamp","datatype":"EDM_L3_Machine1,123","value":"1694688519848","success":false}]';

Result

The stored procedure will verify that the provided values are correctly formatted and then write them into the table PROREC_ProRec_Transactions. This will trigger their immediate processing. The result can be read back from the log table PROREC_ProRec_Log.

Below is an example using T-SQL in SQL Server Management Studio:

SELECT TOP (100) [LogID] ,[LogType] ,[LogProcedure] ,[LogEntry] ,[LogTime] FROM [LE_ProductionRecord].[dbo].[PROREC_ProRec_Log] Order by LogID Desc;

With the result returned

Document image


For more detailed logging, enable the "Debug_Log" option for verbose logging as described in Reading out the Application configuration of Litmus Production Record Database and Modify Application Configuration Items