cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Thingworx mashup auto refresh on data table update/add/delete entry

VR_10133499
14-Alexandrite

Thingworx mashup auto refresh on data table update/add/delete entry

Hi, 

I have a mashup that displays data from a Data table. I need mashup to auto refresh/update data whenever a row is added/deleted/updated in the Data table.

I can use auto-refresh function, but i need data to refresh only in case of changes to row in Data table.

 

 

 

ACCEPTED SOLUTION

Accepted Solutions
VR_10133499
14-Alexandrite
(To:Velkumar)

Taking help from your comments, this is what i did:-

 

  1. I created a property called 'mashup_updater' in helper thing, which i update with timestamp whenever data table is updated using subscription on data table.
  2. I created a container and put 'text' widget in that container. Then binded the 'text' with 'mashu_updater' property and enabled 'automatically update...' 
  3. Then on the change event of 'text' widget, i called a service to get latest data from data table and update the mashup.

View solution in original post

10 REPLIES 10
Velkumar
19-Tanzanite
(To:VR_10133499)

Hi @VR_10133499 

 

Currently, we don't get any events triggered when DataTable gets altered. Based on how you are altering DataTable we can find some workaround.

 

Could you please explain when data will be added/deleted/updated in DataTable?

 

/VR

VR_10133499
14-Alexandrite
(To:Velkumar)

Hi, 

I have a subscription on an entity from AMU application. whenever a new alarm is created in AMU application an entry is made in data table for the alarm using the subscription code.

Now whenever an entry is made in data table i need to refresh my mashup to show latest status of datatable.

Velkumar
19-Tanzanite
(To:VR_10133499)

Hi @VR_10133499 

 

  1. Create a DateTime property in DataTable say 'lastUpdatedTime'
  2. Whenever DataTable gets altered, update this property value with an altered timestamp value
  3. In mashup, put a DateTime Picker and make it invisible (which will be used for lastMashupRefreshedTime)
  4. Get 'lastUpdatedTime' property value in mashup ( use autorefresh function to fetch value )
  5. Create a validator function that checks lastMashupRefreshedTime lastUpdatedTime property
  6. If lastUpdatedTime  is greater than lastMashupRefreshedTime, using validator true event to pull data from DataTable 
  7. Update lastMashupRefreshedTime  value with lastUpdatedTime time

In this case, you will be using the AutoRefresh function but you won't query the dataTable value frequently.

 

/VR

VR_10133499
14-Alexandrite
(To:Velkumar)

There are 2 problems in this approach:-

1) adding a dummy/invisible widget breaks the existing layout of the mashup, invisible widget also takes some space in the UI.

2) It is still based on auto refresh but I need mashup to be refreshed instantly on data table update.

Velkumar
19-Tanzanite
(To:VR_10133499)

@VR_10133499 

 

  1. You can try reducing widget size.
  2. As I said it's a workaround. Currently, we don't have any event to identify DataTable changes so it is difficult to implement your requirement

/VR

VR_10133499
14-Alexandrite
(To:Velkumar)

Taking help from your comments, this is what i did:-

 

  1. I created a property called 'mashup_updater' in helper thing, which i update with timestamp whenever data table is updated using subscription on data table.
  2. I created a container and put 'text' widget in that container. Then binded the 'text' with 'mashu_updater' property and enabled 'automatically update...' 
  3. Then on the change event of 'text' widget, i called a service to get latest data from data table and update the mashup.

Hi @VR_10133499 ,

 

I am following your Post as I am also looking for the same solution. I wanna ask you how did you automatically updated the text field value on the mashup. Can you pls elaborate on that.

 

Thanks in advance.

VV

Technically speaking (and not changing the workaround suggested below), if you are speaking about ThingWorx Data Tables, they do have events for row CRUD operations:

VladimirRosu_0-1691055243376.png

The issue though, is that these events are server-side, perfectly usable in subscriptions, but unusable for client-side (mashups).

You can not trigger a Mashup activity (eg: service execution) based on a server-side event (even if they share the same name, "event", they happen in different places and are incompatible with each other).

If you're speaking about pure SQL tables. then it is correct we don't have directly in ThingWorx a way to detect when a CRUD event happened, but you can definitely create a trigger in PostgreSQL for example, that will issue a REST call to ThingWorx to let it know an add event happened (though this approach is not useful here, more in cases when rows are created by other systems).

There is another workaround you can use:

  • create a session variable, type DateTime
  • In backend, update this DateTime variable each time when a new row is added / deleted
  • Use an AutoRefresh to execute the GetGlobalSessionValues

I suggest following Velkumar's approach, as at the end of the day you will find a way to reduce the widget impact on the layout and if you set the AutoRefresh at 1 second interval, it won't have such a big impact on the system.

 

Hi @VladimirRosu 

 

I have a small question about Session Value. If User1 updates the DataTable and session value gets updated for User1. Will User1's session value be accessible by User2?

 

/VR

 

Hi @Velkumar ,

I'm sorry about the confusion, I did not read carefully all my reply before posting.

You can disregard this part below because it is effectively the same as your workaround.

I started writing it, then realized while writing it was not really useful, but forgot to delete it.

 

"There is another workaround you can use:

create a session variable, type DateTime
In backend, update this DateTime variable each time when a new row is added / deleted
Use an AutoRefresh to execute the GetGlobalSessionValues"

Announcements


Top Tags