Page doesn't refresh after performing an update query

Hi there.

I'm working with Ignition 8.1.24.

I created an update named query and execute it in the script using system.db. runNamedQuery.
The function call always throws an error: The query did not return a result set.
But the manipulations in the data base work. The function obviously just has problems writting the result (in this case it should be the amoung ot the affected rows).
When I catch the error in the script, everything wokrs without issues, but I don't see the result in the view - I have to change something on the page or to set the data polling to 1 second or something to see the result of what my script does.
Refreshing the page via script at the end also doesn't change anything on the situation.

To me it looks like a bug but I'm not sure.

Does anybody know this behavior?

Best
Alex

Use refreshBinding in your script like below:

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

image

1 Like

It doesn't help. But thank you.

Can you explain in more detail what is exactly your requirement?

Ignition Vision or Perspective?

But that's the solution, though. So if it doesn't work, it means you missed something somewhere... and we can't help with that if you don't tell us what you did and what didn't work.

2 Likes

Also, is the query type set to 'Update Query' in the named query editor?
image

1 Like

Perspective.
I have a table with some data between two dates, which I can choose. I can select a row from that table and send the data from that row to another system using a button I created. In the table there is a column telling me, how many times I already sent the data from a certain row to the other system. At the end of the sending process I run an update query and add 1 to the number in that field. The query makes the updates I want, but throws me an error message: The query didn't give any result.
If I catch this error in the script, everything works fine, only I dont see any result, unless I do something on the page (like choosing a different date) or set the polling on the table to a small number.
Example:
There's 2 in the field, I press the button, the query is run: I still see the 2.
In my data base in the same line I see 3, which is the expected result.
I refresh the page manually and only then I can see that 2 changed to 3.
Your suggested solution with adding refreshBinding at the end of the script behind the button did not change anything.

Yes, I did that.

We might need to see some screenshots and code snips that demonstrate what you are doing.

@Priyanka.Khandge is correct... the refreshBinding is the proper way to refresh a binding in Perspective, but without knowing which object has which it is hard to point you in the correct direction.

1 Like

Here is the code:

def runAction(self, event):
import ast
	obj = some file path
	obj.Payload =  
       ast.literal_eval(self.getSibling("Table").props.selection.data[0].Payload)
obj.updateSelectedRow(str(self.getSibling("Table").props.selection.data[0].UUID))
	obj.execute()
	self.refreshBinding("custom.settings")

The last line I added today.

The fuction updateSelectedRow does just:

params = {"UUID":UUID}
system.db.runNamedQuery("sgl/interfaces/sap/SapTransactionLog_Update",params)

The execute function is just about sending data to SAP and works without issues.

OK. So this

params = {"UUID":UUID}
system.db.runNamedQuery("sgl/interfaces/sap/SapTransactionLog_Update",params)

Is what is querying the database for the number you want to see? Is that the query that is giving your errors?

This one just adds 1 to a certain field.
It also gives me an error saying that the query did not return a result.
But at the same time I see in the data base, that the the data are changed and the query actually did; what it was supposed to do.

OK. Let's start at this query then.

Can you post the query? And a screen shot of how you have it defined in the Named Query?

Here the query:

UPDATE Interfaces_SapTransactionLog
SET Sent2SAP = ISNULL(Sent2SAP,0) + 1 , Sent2SapOn = ISNULL(Sent2SapOn,GETUTCDATE())
WHERE UUID = :UUID

OK since that is an update query, nothing will be returned from that query.

You want the value of Set2SAP after that update is done correct?

If so, you will need to do the update and then do a separate Select query for that same data to display.

I see.
I guess that's the answer to my question.
Thank you!

1 Like

No problem. If you continue to have issues please just update this topic.

NB: ast.literal_eval is a performance nightmare. It's unlikely you need it at all, but you can likely replace it with the dict() builtin for the same end result with much better performance.

Well.. I'm guessing your script is executed from a button. So, that means self is the button.
You're trying to refresh the custom.settings property on the button itself... Which I doubt is what you actually want to do.
You need to use .refreshBinding on the component that has the binding.

I was gonna say... It's not the first time I see ast used for things that have nothing to do with actual ASTs. Where do people even find that idea ?

2 Likes

I don't want to actually say it but I'm guessing it ends in "GPT"

6 Likes