Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hello there, folks!
I've been successfully able to update a boolean value in Thingworx from Vuforia Studio without problems. I've made the correct bindings and everything, as you can see in this post: https://community.ptc.com/t5/Studio/Writing-Values-to-Things-From-Vuforia/td-p/616754
However, I'm not being able to update the same value from a script command (such as the click of a button).
Below, an example of the syntax I'm using to update the values:
$scope.app.mdl['thingName'].properties['booleanProperty'] = false
Nothing is being shown in the app logs or any other ones. Am I doing something wrong??
Thanks!!
Hi @rgomes ,
I did also have difficulties in the past to set a Thingworx property form JavaScript directly via assignments via the object syntax. I tried sometimes but I also did not get it working. So I used some services for the same task. So defined a function which I called in my code:
...
 $scope.setCompVis($scope.modelitem_idCompId('modelItem-aus-5'),false);
...
or
$scope.view.wdg['modelItem-innen']['visible'] =true;
    $scope.setCompVis($scope.modelitem_idCompId('modelItem-innen'),true);
....
Where the function definition is something like this. Here I will use 2 different services depending on the value - for true or false (set or unset) {actually is not the best solution -but so you can avoid the sending of true or false as function}
$scope.setCompVis = function(Comp_id,val) {
   
  if(val==true)
    var serviceStr='app.mdl.DoorControlProces.svc.setCompIdVisibility';
  else
    var serviceStr='app.mdl.DoorControlProces.svc.unsetCompIdVisibility';
   
  var JsonObj=  { "Comp_id":Comp_id};
  $scope.$applyAsync(function() { $rootScope.$broadcast(serviceStr,JsonObj);})
};
//////////////////////////////////////////////////////////////////////////////////////
There I need only to send the value of the component id / occurrence path / as sting.
Another way I tested is to use some Rest API call like this :
//////////////////////////////////////////////////////////////////////////////////////
$scope.setCompVis = function(Comp_id,val) {
  if(val==true)
    var serviceStr='setCompIdVisibility';
  else
    var serviceStr='unsetCompIdVisibility';
var req = {
"method":'POST',
"url":'/Thingworx/Things/DoorControlProces/Services/'+serviceStr+'?Appkey="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" HTTP/1.1',
"Host": 'mrerot7o.studio-trial.thingworx.io:8443',
"Content-Type": 'application/json',
 "AppKey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
"Cache-Control": 'no-cache',
"Postman-Token": 'xxxxxx-xxx-xxxx-xxxx-xxxxxxxxx',
  "headers": {
    "authorization": "Basic Og==",
    "content-type": "application/json",
     "AppKey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
    "cache-control": "no-cache",
    "postman-token": "xxxxxx-xxx-xxxx-xxxx-xxxxxxxxx"
  },
  "processData": false,
 "data": "{\n\t\"Comp_id\":\""+Comp_id+"\"\n\t\n}"
};
$http(req).then(
function(response) {;}, 
function(response){;}
               );
}
//////////////////////////////////////////////////////////////////////////
Where I tested the call first in the REST API Postman tool and then did call what the postman did generate embed into a $http request. This is difficult to be generated and need some testing by trial and error but when it works then it works very stable. - I do not think that is a good solution but just to mention it because when it works then it works stable and often the only way I found
But maybe, someone could share also his experiences if there is more easy / efficient way…
Hello, @RolandRaytchev!
Thanks for the fast response. Due to schedule issues I won't be able to test your solution in the next few weeks, but I'll send you a feedback as soon as possible!
Thanks again!!
