Skip to end of metadata
Go to start of metadata

The may be a case to bring in data from an external system.  This KB describes the process to bring data from a database table into the SPC module.


  1. Ensure you have a connection to the external database in Ignition: https://docs.inductiveautomation.com/display/DOC81/Connecting+to+Databases
  2. Create A Sample Definition to represent the data to be sampled: Creating Sample Definitions
  3. Modify the following script example to match your DB, Sample Definition, and Location Path to match your environment:
Sample Via DB
from java.util import Calendar

query = 'SELECT data, timestamp where id = ?'
#https://docs.inductiveautomation.com/display/DOC81/system.db.runPrepQuery
data = system.db.runPrepQuery(query,['1'], 'mydbname')

locationPath = 'New Enterprise\\Site 1\\Area 1\\Sample Location'

# sample definition name
defName = 'DB Example'

#Sample Object Documentation - https://help.sepasoft.com/docs/display/SEPA/Sample

for row in data:
	
	#create a new sample from the definition
	#https://help.sepasoft.com/docs/display/MHD/system.quality.sample.data.getNewByDefName
	sample = system.quality.sample.data.getNewByDefName(defName, locationPath)
	 
	#NOTE: sample values are passed as strings, they are converted internally to the proper data type.
	#"data" is the column name, replace with your column name where the sample data will be taken from.
	att1Val = row['data']
	
	#NOTE: sample values are passed as strings, they are converted internally to the proper data type.
	sample.setSampleData(1, 'Attribute1', str(att1Val))
	
	#Sets the date and time that this sample was entered.  This example sets the time to now.
	cal = Calendar.getInstance()
	sample.setSampleTakenDateTime(cal)
	
	#Sets the date and time that this sample was entered. If sample was taken historically, this is how to set when the sample was taken if available in the db
	cal.setTimeInMillis(row['timestamp'])
	sample.setEntryDateTime(cal)
	
	#If shift is will be used for post processing analysis
	#sample.setSequenceDate(2)

	sample.setApproved(True)
	
	#save the sample by calling it's update method
	system.quality.sample.data.updateSample(locationPath, sample, True)
  • No labels