Variable doesn't get updated if custom widget uses asynchronous call (REST)

Hi,
I’ve built a custom widget (thanks to quentin ) that retrieves a variable from an activity, by using Bonita REST API.
The variable is displayed by the widget, but I want it to write that value into a variable defined in the editor.

So I did a bidirectional binding. The variable never gets updated. By testing, I found out that the problem seems to lye in the asynchronous call. I’ve tried several things ($scope.$apply, variable = return $http…) but did not succeed.

Any ideas?
Here is the controller code:

` function ($scope, $http) {
// call the bonita API
$scope.theResult = ‘’;
$scope.properties.resultingVariable = $scope.theResult;
$http.get($scope.properties.APIUrl+$scope.properties.activityId+‘/’+$scope.properties.variableName).then(
function successCallback(response) {
$scope.theResult = response.data[$scope.properties.propertyToDisplay];
console.log(‘hello’);
$scope.properties.resultingVariable = response.data;
}
);
}

}`

And the model

<div>{{ theResult }}</div>

resultingVariable is a “bidirectional bond”.

Thank you!
Valerio

It works - I’ll upload the custom widget as a new project

Can you export the custom widget and upload it somewhere ? It will be easier to find a solution if I can experiment with the widget

Regards

Good idea, here you go:
http://valerioneri.de/widget-getActivityVariable.zip

I took a look at your widget but I can’t see what’s wrong, sorry. Maybe the problem comes from your page

Hi Quentin, it means that in your experiment the variable you set into the binding is updated?
Ok I’ll need to check that, quite odd…

Hi Quentin, it means that in your experiment the variable you set into the binding is updated?
Ok I’ll need to check that, quite odd…

Yes, I did a really quick test with a single task process and it worked

You’re right, it works - seems to be something with the page!