Skip to main content
6-Contributor
May 18, 2023
Question

How to "auto refresh or reload" mashup data grid based on the change in the data.

  • May 18, 2023
  • 1 reply
  • 3537 views

I need to auto refresh or reload a mashup based on the change in the data.

 

The mashup is made up of a data grid (advanced grid widget) that gets the data using a custom service that calls an REST API. Instead of calling REST API periodically to get the latest data and refresh mashup, I need to "subscribe", probably connecting thru websocket, so the mashup gets updated (advanced grid needs be refreshed) by calling service when there is new data available. Any solution for this mechanism?

 

I have seen option of automatically updating/refreshing the grid data using the GetProperties "Automatically update values when able checkbox" in combination with ServiceInvokeCompleted event (which is based on websocket connection to property changes that mashup is subscribed to), but even then I am not sure how to update a property based on change in source data.

 

 

 

1 reply

17-Peridot
May 19, 2023
  • What is the actual data source for that custom service?

You can leverage the GetProperties ["Automatically update values when able checkbox" ] service with the actual data source change event.

6-Contributor
May 19, 2023

Thanks! for the response, The actual data source is a Data base which I am accessing it using the REST API which returns data in JSON format. Like I said earlier, instead of periodically calling this API, I would like to notify when the data is changed. I am planning to use thingworx mashup as the GUI to display the changes in Database using the REST API. 

Even if I create a "dummy" property to leverage GetProperties Auto update checkbox, I am not sure how to change automatically the property value on change of data in the data base, without calling the API periodically.

Also, there is message bus on the server hosting REST API which gets notified change in data, is there a way to subscribe to that from thingworx to update the data on mashup?

That's why I am looking to see if there is subscription based mechanism like using WebSocket connection.

 

10-Marble
May 24, 2023

Hi @SS_10617248 ,

 

If I understand the question correctly, you want to know how to notify Thingworx that data has changed in the DB.

Unfortunately I don't see a straight forward way to do this.

 

Typically it would be a middleware that pulls and pushes data (this is something that a lot of people already use Thingworx for. So another middleware might not give you much benefit in what you are trying to achieve, unless it is a microservices approach and there are a lot of tables and data.)

 

Another option might be to try and install a database utility to make a REST call inside a trigger function which listens to an insert or update action on a table. Personally, I have not tried this.

Check out this stackoverflow query about something similar: calling-restful-web-services-from-postgresql-procedure-function 

This is assuming your DB is PostgreSQL. I'm sure you can find something similar for other DBs as well.

 

If this works, then all you need to do is create a service on Thingworx which get's notified of a change by the DB trigger function via REST and then pulls the new Data and stores it in a property. You can then use the GetProperties Auto update feature in the mashup by listening to the property value.

 

Do let me know of the outcome, if you are going to do this. As theoretically it should work, but when fellow community members actually solve it and confirm the solution, then it's always better knowing what can be done next time successfully or whether this approach should be avoided.