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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

ThingWorx web component (Polymer) - How to use services?

JK_10164157
7-Bedrock

ThingWorx web component (Polymer) - How to use services?

Hi all,

 

Our application relies heavily on custom extension widgets for showing large datasets in a card style layout.

We understand the mechanics of using properties and events, but are not able make the 'services' part work.

It would make development a lot easier if services could directly be triggered from mashup events. Currently we have a workaround to use change events on boolean property, but prefer to understand the 'service' method.

 

Documentation on this is currently quite limited:

Packaging a Web Component as a ThingWorx Widget - ThingWorx Web Component SDK - Polymer (ptc.com)

 

Any suggestions to guide us is in the right direction would be appreciated, thanks in advance!

2 REPLIES 2
PaiChung
22-Sapphire I
(To:JK_10164157)

Can't quite help you, but have you taken a look at for example the ootb 'Button' Widget to see how it does an action?

I haven't used the webcomponent SDK yet, but from my understanding, you should not trigger directly a server-side Service from the Widget runtime code. You should instead trigger an event, which, in turn, will trigger any other server-side Service or client-side Function via the bindings method.

For that to happen you don't need to modify the widget, just to make sure it emits the Events, like the ones in the screenshot below.

VladimirRosu_0-1719996355046.png

Technically you can define also widget Services, but those should do something in the scope of the client (eg:  alter the widget DOM, set a widget property if needed, etc).

Below it's a snippet for the widget service "ClearSelectedRows" from the GitInfotableSelector widget:

 case 'ClearSelectedRows':
                    thisWidget.updateSelection('Data', []);
                    currentSelectedRowNumber = undefined;
                    thisWidget.setProperty('NoRowsSelected',true);
                    thisWidget.setProperty('AnyRowsSelected',false);
                    break;

This type of service can be called in the same fashion, via the binding mechanism, but you should not call services directly from here.

Announcements


Top Tags