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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Async Service as Promise/Await like with Events and Subscriptions

Teemu
4-Participant

Async Service as Promise/Await like with Events and Subscriptions

Hi!

 

I have a few huge data packets I am fetching through REST Api and I would like it to happen separately with async functions so users do not have wait for all of them to be fetched.

 

So what I have tried to do is: Create a custom async service which fires an event after data has been fetched, that event is listened by subscription which calls a custom Service which updates data in a Thing Property. So my question is: is there any other way to get that data to Mashup instead of using an Auto-Refresh widget.

 

What I hoped I could accomplish instead of using an Auto-Refresh widget:

 

1. Have a reference to a widget in a Service from where I could update the widget or bind data to it.

2. Call Mashup's Refresh function (at least Mashup["mashup"].Refresh won't work)

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

It's an infotable property? usually it isn't a good approach, but anyway, in order to get the DataChange event thrown on a Infotable event you should set it as DataChangeType=ON and when you set it's value you should set it explicitly:

var clonedInfotable = Resources["InfoTableFunctions"].Clone({ t1: me.myInfotableProperty  });

clonedInfotable.AddRow({ newValues....});

me.myInfotableProperty = clonedInfotable; // <-- Explicit update of the property

 

View solution in original post

4 REPLIES 4

You can use GetProperties on the mashup to get a push update when properties are updated instead of a continuous pull with AutoRefresh.

 

Here the documentation: http://support.ptc.com/help/thingworx_hc/thingworx_7_hc/#page/ThingWorx_Help_Center%2FThingWorxHelpCenterDITAFiles%2FMashupBuilder%2FMashups%2FMashupAutoUpdate.html

Teemu
4-Participant
(To:CarlesColl)

Forgot to mention that I tried that, but it doesn't work. At least if it doesn't need anything else than bind GetProperties.myInfoTable to Grid in Mashup and select  'Automatically update values when able' from GetProperties properties. Grid remains empty.

 

Don't know if it has something to do with the fact that I add the rows to info table from service?

It's an infotable property? usually it isn't a good approach, but anyway, in order to get the DataChange event thrown on a Infotable event you should set it as DataChangeType=ON and when you set it's value you should set it explicitly:

var clonedInfotable = Resources["InfoTableFunctions"].Clone({ t1: me.myInfotableProperty  });

clonedInfotable.AddRow({ newValues....});

me.myInfotableProperty = clonedInfotable; // <-- Explicit update of the property

 

Teemu
4-Participant
(To:CarlesColl)

Yes.

 

I had the DataChangeType=ALWAYS cause that fires ALWAYS, hah.


Never thought about setting info table explicitly, of course that should do it. Silly me.

 

Thanks for help!

Top Tags