Skip to main content
1-Visitor
April 22, 2020
Question

How to create a subscription for boolean property?

  • April 22, 2020
  • 1 reply
  • 2918 views

Hi all

I am new in javascript coding and hope some of you can help me in proceeding with my problem.

I am using ThingWorx 8.3.7.

 

I want a label-widget to be displayed with either the text "Connected" or "Disconnected" on my dashboard to show if the machine is connected or not.   

I am working with two properties:

  • Boolean: isConnected
    • when boolean is true: the text should be "Connected" 
    • when boolean is false: the text should be "Disconnected"
  • String: ConnectionStatus

I have tried to create a simple subscription (see script and picture below) with the if/else statement, but when the mashup is loaded the label is not visible with any of the texts. I used the GetPropertyValue service and bound the ConnectionStatus string to the label-widget.

 

Am I missing anything or writing the script/statements wrong? (eg the booleans false/true value) Or is there a better way to achieve this? 

Please let me know if you need further information 🙂

Thanks, Michelle

 

 

if(eventData.newValue.value === true) { 
 me.ConnectionStatus = "Connected";
} else { 
 me.ConnectionStatus = "Disonnected"; 
}

 

 

Subscription.JPG

Binding.JPG

1 reply

1-Visitor
April 23, 2020

Try GetProperties instead, and check the box "Automatically update values when able" that why the connection status will update "automagically" when it connects/disconnects. Also remember to trigger the GetProperties service at Mashup Loaded or alike.

 

Regards,

Carles.

miwhow1-VisitorAuthor
1-Visitor
April 27, 2020

Thanks for your reply Charles,

I have triggered the Mashup Loaded and tried to use GetProperties instead, but no text is shown here as well... 

 

I also tried to bind the boolean "isConnected" to the label widget instead, which then shows the text "false".
But I want it in this case to be "disconnected", and that is why I created the script using the string ConnectedStatus, which should be bound instead. But when doing so the label is empty

Can it be an error in the script?  

 

Best regards,
Michelle

1-Visitor
April 27, 2020

Hi,

 

ConnectionStatus changes when isConnected changes? I mean seeing it from the composer? I that's true, then which it's the ValueChange policy on ConnectionStatus it's set to VALUE?