Writing user input text from PMI to db

I am trying to get user loaded text from PMI inserted into a db. I need it to write to the db on a change in a sensor value ( on/off ). I have created the table and have written the attached script:

if event.source.value == '1': fpmi.db.runUpdateQuery("INSERT INTO Shower_Data (description, date_lot, t_stamp) VALUES (event.source.parent.getComponent('Inflator Desc Sensor 1').text, event.source.parent.getComponent('Date_Lot Sensor 1').text, GETDATE())", 'Automation_Eng_Group')

I am trying to assign this to a number label on a property change action.

Carl – How bad have I messed this up?

Thank you,



You are really close! If you want to capture those values when the numeric label changes, you want something like

[code]#It’s less confusing if you pull out the variables
desc = event.source.parent.getComponent(‘Inflator Desc Sensor 1’).text
dateLot = event.source.parent.getComponent(‘Date_Lot Sensor 1’).text

#only execute the code if the value property changed
if event.propertyName == “value”:
#only execute if the newvalue is 1
if event.newValue == 1:
fpmi.db.runUpdateQuery(“INSERT INTO Shower_Data (description, date_lot, t_stamp) VALUES (desc, dateLot, GETDATE())”, ‘Automation_Eng_Group’")

There’s a button in the lower right of the event configuration screen that looks like two stacked “^”. If you click it, you can see all the values you have available for that event (ie propertyName and newValue).

Do you need to store this in a specific database location, or just in the database? Are you using FactoryPMI 3.0.x?

With SQLTags you can just create a db tag and bind the numeric label and input to it. In fact, just drag the tag to the window and it will do that for you.

Thank you, Robert.

That worked great!

Nathan - I am still using an older version of PMI (2.2.0).

I will get things updated and try it your way as well.

Thank you.

One other item related

How do I keep the text in the text fields after the window has been closed?

Set the Window’s (expert) Cache policy to Always. This will maintain the text field in memory if you close a window then re-open it.

If you need to maintain this between separate clients and closing the app, store it in the database or SQLTags.

One other item related

How do I keep the text in the text fields after the window has been closed?[/quote]