I am trying to run an update query on a button press that would switch a value in the table based on 2 parameters. Here is my query:
and here is the script I am running on button press:
> def runAction(self, event):
> # Set Up Params to pass
> parameters = {'MachineID':str(self.parent.parent.getChild("FlexContainer").getChild("FlexContainer").getChild("TextField").props.text) , 'UID':self.parent.parent.getChild("FlexContainer").getChild("FlexContainer_0").getChild("Dropdown").props.value}
>
> # Run Query
> system.db.runNamedQuery('FlaggedTest', parameters)
But when I press the button I get this error in my logs on the gateway:
Any ideas on what I am doing wrong?
The bottom of the error log says that you're trying to coerce 'E999' to a number.
I suspect that you have fed 'E999' into the UID parameter which is expecting an Int8 datatype.
1 Like
That was an obvious overlook by me, Thank you!
parameters = {
'MachineID':str(self.parent.parent.getChild("FlexContainer").getChild("FlexContainer").getChild("TextField").props.text),
'UID':self.parent.parent.getChild("FlexContainer").getChild("FlexContainer_0").getChild("Dropdown").props.value
}
You can greatly improve the legibility and robustness of your code by eliminating all the parents, grandparents, children, cousins, uncles and aunts from the expressions as follows:
- On the view, create two custom properties, "machineId" and "uid".
- Bind the text field and the dropdown value properties to their respective custom props. Make the bindings bidirectional.
- Now your parameters dictionary becomes:
parameters = {
'MachineID': view.custom.machineId,
'UID': view.custom.uid
}
It's much easier to read and it will survive a divorce, remarriage and/or legal adoption of the children by other containers.
Technically the way you've written the application is "brittle" and moving any of the referenced components will break the property paths. This way the components always bind to something on the view itself (the custom props) and they can't move. They'll always be there for you. (Just like grandma!)
3 Likes