Hey Community, So I have this service and it has four parameters and one of them is intervalCount, which i have given here 150 but now i want to give an additional interval which would be 50 so i want to run this service twice with 150 and 50 but on success both will give me results. I am confused a bit. what can be the best approach here should i change the service architecture on the thingworx side? to accept as an array or should i do something on experience side to make it run. any ideas are welcome. this service runs everytime i start the expereince and what this service is doing that it takes interval count and divide by total entries to give me modus and if its 0 then i know its 150 product so that i do something on exp side
thanks
$scope.every50thEntryCounter = function () {
twx.app.fn.triggerDataService("QControl.Data.Helper", "intervalCountForProductCategory",
{
// Hand over variables to the service
lineName: $scope.app.params['lineName'],
Location: $scope.app.params['lineLocation'],
productCategory: $scope.app.params['productCategory'],
intervalCount: 150,
}
);
$scope.$root.$on("intervalCountForProductCategory-complete", function (evt, arg) {
let result = $scope.app.mdl["QControl.Data.Helper"].svc["intervalCountForProductCategory"].data;
Hi @MA8731174 ,
at the first view the usage parameter intervalCount could be understand a little ambiguous – so possibly that you have an setInterval or $interval callback. But so far I see the code you will call a TWX service and then you a waiting on the result in the …-complete event? Right? So far, I understand the question here is there is no clear when you call one time the method with 150 and one time with 50 values for the parameter which event corresponds to which call? Right?
An another much simpler approach will be to have different TWX methods – simple copy the method with different name , add it to Vuforia Studio External Data section and call it with second call and define a second event
So possibly there are also possibilities … e.g. that you TWX service will call a method what count that and then the event will called onet time with the content the data for all called events – in some way separable as InfoTable or Json object. I will thing that will be more difficult to be designed but you will reduce the event calls.
Thank you for the insights but let me explain even further so lets say i have a view called Home.js and i want to call the same service of thingworx twice ok with different params but on complete it will just gives me response from one api because complete will change the response for the second call to first call. because its a complete event for the same service which is calling twice but with different params. how can i get two time different responses and can save them in for example a variable.
$scope.every50thEntryCounter = function () {
twx.app.fn.triggerDataService("QControl.Data.Helper", "intervalCountForProductCategory",
{
// Hand over variables to the service
lineName: $scope.app.params['lineName'],
Location: $scope.app.params['lineLocation'],
productCategory: $scope.app.params['productCategory'],
intervalCount: 50,
}
);
twx.app.fn.triggerDataService("QControl.Data.Helper", "intervalCountForProductCategory",
{
// Hand over variables to the service
lineName: $scope.app.params['lineName'],
Location: $scope.app.params['lineLocation'],
productCategory: $scope.app.params['productCategory'],
intervalCount: 150,
}
);
$scope.$root.$on("intervalCountForProductCategory-complete", function (evt, arg) {
let result = $scope.app.mdl["QControl.Data.Helper"].svc["intervalCountForProductCategory"].data;
Thanks @MA8731174 for the clarificaiton. Understand now to use case. That means that issue occured only when you call the service second time before you got the results from the first api , and the problem is that only one result is handeled in event, even that what is first completed
I do not believe that we can manage that with one service in vuforia Studio. Possibly you can define a second service in TWX e.g. intervalCountForProductCatergory2 /let say some kind of wrapper which call possibly the same service in TWX intervalCountForProductCatergory). I think in Thingworx there should not be a problem when you call the same service from differnet TWX services inside a small time range - all will work indeptendly and will completed. So then you will have in the external data 2 different services - and the corespoinding 2 different service events. But all both services will simple past the arguments to the same Thingworx service. I would believe that will work. Thanks
One approach I've used when I want something to happen after repeated event notifications is a simple counter to keep track. The logic goes something like this:
1) Set a $scope variable to the number of invocations you will make
2) In the $scope.$on() event listener, decrement the counter, and only execute the final code if the counter reaches zero (i.e. all expected invocations have resolved).
I use this sometimes when I want to trigger something after all models in the experience have loaded. So, something like this:
// suppose we have 5 models in the experience
$scope.modelcount = 5;
// we want to take some action only after all models have loaded;
// this will execute every time a model is loaded, so count them down
$scope.$on("modelLoaded", ()=>{
$scope.modelcount--;
if ($scope.modelcount == 0) {
// all done loading models, do whatever we need here
alert("All models loaded");
}
});