Write to DB with Save Button Script

def runAction(self, event):
	# Grab the values to place in new DB row.
	Parent = self.parent.parent.parent.getChild("containerLineMachine").getChild("labelLineName").props.text
	SAP = self.parent.parent.parent.getChild("containerSapLabel").getChild("SAP Label").props.text
	CommonName = self.parent.parent.parent.getChild("containerLineMachine").getChild("labelCommonName").props.text
	Note = self.parent.parent.getChild("CoordinateContainer").getChild("NewCommentTextArea").props.text
	 
	# Use those values in the Insert Comment Named Query.
	system.db.runNamedQuery("InsertMachineComment", {"myParent":Parent, "mySAP":SAP, "myCommonName":CommonName, "myNote":Note})
	 
	# Refresh the table to immediately bring in the new row.
	system.db.refresh(event.source.parent.getChild("CommentHistoryTable"), "data")

Ok, what am I doing wrong here?

On Click of the 'Save' button appears to do nothing. This is an event script onActionPerformed on my 'Save' button.

1 Like
1 Like

Posting a picture of code without properly formatted text following in the text?

On a serious note though:

I see from your code that you are working in perspective.

system.db.refresh() is only scoped for vision. You're looking for self.refreshBinding()

P.S. I'm not retyping your script.

1 Like

If you look at the logs in the gateway there is a good chance it will tell you exactly what the problem is, or at least point you to the line in fault.

2 Likes

Tip: a handy way to debug a script is,

  • Create a memory tag, say, projectNameDebug.
  • Where you need to debug in your script add in a write to the tag:

system.tag.writeBlocking(["[default]projectNameDebug"], ["onActionPerformed fired."]

This will show you the last debug before the script stopped.

https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking

1 Like

Good insight thank you, I will start creating this habit!

Not discrediting this by any means, but why would you do this when you can use a logger to log to the wrapper file, or for temporary debugging use system.perspective.print() (or just print for vision) and print messages directly to the output console?

5 Likes

I find loggers difficult to use. Switch to the browser, stop the live view, try and find the logger, scroll right across because it doesn't wrap.
The tag can be monitored on the Tag Browser pane.

Maybe I've missed something in my learning Igniton but I've searched and never found a good tutorial on the logger. I have a tremendous fund of ignorance to draw from!

One advantage of the writing-to-a-tag approach is you get feedback inside the designer; no need to open the gateway webpage. But it is definitely easier to get richer info via the logs.

1 Like

I share that trait.

I have this bookmarked:

Of particular interest is the last part of that. Very helpful, since I almost always have the developer tools open when working in perspective.

1 Like

Heh. I use a 2nd 4k monitor, and use tail -f .../wrapper.log from an SSH connection to the gateway.

Highly recommended (really).

1 Like

Nice. My laptop seems to top out at an external 4k plus an external FHD. Even a 1900x1200 at 30Hz makes it wonky.

Ok I am struggling to get the table to refresh after save:

def runAction(self, event):
	# Grab the values to place in new DB row.
	Parent = self.parent.parent.parent.getChild("containerLineMachine").getChild("labelLineName").props.text
	SAP = self.parent.parent.parent.getChild("containerSapLabel").getChild("SAP Label").props.text
	CommonName = self.parent.parent.parent.getChild("containerLineMachine").getChild("labelCommonName").props.text
	Note = self.parent.parent.getChild("CoordinateContainer").getChild("NewCommentTextArea").props.text
	 
	# Use those values in the Insert Comment Named Query.
	system.db.runNamedQuery("Machine Comments Panel/InsertMachineComment", {"myParent":Parent, "mySAP":SAP, "myCommonName":CommonName, "myNote":Note})
	 
	# Refresh the table to immediately bring in the new row.
	system.refreshBinding(self.parent.parent.getChild("CommentHistoryTable").props.data)

	# Clear text field
	self.parent.parent.getChild("CoordinateContainer").getChild("NewCommentTextArea").props.text = ""

Gateway log tells me Line 12 "object has no attribute 'refreshBinding'"

Try,
self.parent.parent.getChild("CommentHistoryTable").refreshBinding("props.data")

https://docs.inductiveautomation.com/display/DOC81/Perspective+Component+Methods#PerspectiveComponentMethods-RefreshingBindings

4 Likes

refreshBinding() is a function on the component object it's self. It isn't a system function.

Assuming that this script is located on the table you are attempting to update, then all you should need is:

self.refreshBinding("props.data")

If not, then you will need to get the path to the table component and then call refresh binding, as @Transistor has shown.