Skip to main content
7-Bedrock
March 12, 2018
Solved

How to invoke the widget service programmatically using js in Thingworx Studio?

  • March 12, 2018
  • 1 reply
  • 6419 views

I will like to invoke the 'showpopup' service of 'Popup' widget from the js function instead of using 'click' event binding. 

Best answer by yleong

Hi,

 

I have found the answer by exploring $scope.app object.

 

The $scope.app do provide property 'fn' that includes the function called triggerWidgetService(widget_id, service_name).

 

The sample script for reference.

$scope.showPopup = function(){
$scope.app.fn.triggerWidgetService('popup-1','showpopup');
}

 

1 reply

17-Peridot
April 2, 2018

Hi @yleong

Could you please provide more details on this scenario? Would you like to invoke the show-popup service from another function written in js file?

yleong7-BedrockAuthor
7-Bedrock
April 11, 2018

Example when a model item is selected, click event will trigger an js function. The function will performs some validation like check current step, after the validation i will like to use js to trigger the 'show popup' service of the new pop-up widget  inside the function. I will like also to use js to trigger the 'play' service of audio widget.

5-Regular Member
April 17, 2018

Hi, 

Here is my suggestion:

  • Edit the <<viewname>>.js file and add a showPopup function to your view that will display or hide your popup:
    $scope.showPopup = function(flag) {
     $scope.view.wdg['yourPopUpName']['visible'] = flag;
    }
  • Replace 'yourPopUpName' with the name of your popup (case sensitive)
  • Save the <<viewname>>.js
  • On you JS Trigger, call the function passing True or False to Display or Hide the PopUp:
    showPopup(true); // Display PopUp
    showPopup(false); // Hide PopUp

 

Hope it helps,

Ricardo