I am working on a popup that will insert data into a database. However prior to storing the data, I would like the script to ensure that all the required fields are filled, and if so the user will need to validate their credentials to prior to the data being inserted into the database. However, I am having trouble with the system.perspective.openPopup function. When I run the script I get the following error on the openPopup line: AttributeError: 'com.inductiveautomation.ignition.designer.gui.tool' object has no attribute 'perspective'
def runAction(self, event):
UDT = self.parent.parent.getChild("UDTFlex").getChild("UDT").props.value
Asset = self.parent.parent.getChild("AssetIDFlex").getChild("Asset").props.value
Users = self.parent.parent.getChild("OperatorsFlex").getChild("Users").props.value
Supervisor = self.session.props.auth.user.userName
Campaign = self.parent.parent.getChild("CampaignID").props.text
Batchid = self.parent.parent.getChild("BatchID").props.text
startTime = system.date.now()
AssetS = str(Asset)
UDTS = str(UDT)
OperatorsS = str(Operators)
SupervisorS = str(Supervisor)
CampaignS = str(Campaign)
BatchidS = str(Batchid)
startTimeS = systeme.date.format(startTime, "yyyy-MM-dd HH:mm:ss")
if UDTS == "" or AssetS == "" or OperatorsS == "":
system.perspective.openPopup('empfieldsPopup', 'empfieldsPopup', showCloseIcon = True, pageID = 'addUDTpopup')
else:
system.perspective.openPopup('authPopup', 'authPopup')
query = "INSERT INTO udtSelect (Asset, UDT, Operators, Supervisor, Campaign, Batchid, startTime) Values(?,?,?,?,?,?,?)"
args = [AssetS, UDTS, OperatorsS, SupervisorS, CampaignS, BatchidS, startTimeS]
system.db.runPrepUpdate(query,args)
system.perspective.sendMessage("refresh", "session")
system.perspective.closePopup('addUDTpopup')
This script is configured on the submit button of the currently opened popup
EDIT: I got the popups to open correctly. There were some minor typos and references preventing the script to run up to the if statement.
However, I want the script to update the database only after the authentication is successful, but I am unsure how to refer to the result of the authPopup into this script.