Skip to main content
15-Moonstone
Aug 20, 2021 5:21 PM UTC
Solved

.js Function Exection on Service Completion

How would I code a function to execute every time a service is completed? I would like to use js instead of bindings.

ailkoAnswer
5-Regular Member
Aug 20, 2021 7:27 PM UTC

To execute javascript code in studio home.js when a TWX service added in the External Data would trigger a "ServiceInvokedComplete" event you can add the following in the home.js to intercept that event and run code that doesn't require leveraging the bindings in studio:

 

$scope.$on('myTWXService.serviceInvokeComplete', function(evt, arg)
{
// do code after myTWXService executes
});

5 replies

ailko5-Regular MemberAnswer
5-Regular Member
Aug 20, 2021 7:27 PM UTC

To execute javascript code in studio home.js when a TWX service added in the External Data would trigger a "ServiceInvokedComplete" event you can add the following in the home.js to intercept that event and run code that doesn't require leveraging the bindings in studio:

 

$scope.$on('myTWXService.serviceInvokeComplete', function(evt, arg)
{
// do code after myTWXService executes
});

Translate
Ike@ACE15-MoonstoneAuthor
15-Moonstone
Aug 24, 2021 2:19 PM UTC

What are the two parameters that are passed into the function (i.e. evt and arg)?

Translate
5-Regular Member
Aug 24, 2021 2:53 PM UTC

This is just the OOTB function definition for the serviceInvokedComplete trigger in Studio, as far as the values I've never needed to leverage them for my usecases or know what their values are but you can use console.log() in the home.js and the values will show up in the Console tab of dev tools. ie console.log(evt)

Translate