cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

fixed decimals

Sruthi
14-Alexandrite

fixed decimals

Hi,

I have some properties connected with remote thing, so the values of the properties will be changing every 5 seconds. I need to round some of the property values to 2 digits after decimal point.

 

I tried writing a subscription with 'Any data change' event and used the code

me.prop1 = me.prop1.toFixed(2);

me.prop2 = me.prop2.toFixed(2);

me.prop3  = me.prop3.toFixed(2); 

but getting errors.

 

Script log:

Error in: [Thing_name].[Subscription_name].javascript service

1 ACCEPTED SOLUTION

Accepted Solutions
nmilleson
17-Peridot
(To:Sruthi)

@Sruthi ,

 

When you try and set a property value that is bound to an Industrial Thing (for example a PLC), ThingWorx will try and set that property ON the thing that is connected.  For example, if your device is sending a temperature value of 20.987654 to the property 'temperature' and then you try and change the property value 'temperature' to 20.99 in ThingWorx, you are asking it to set that temperature ON the device.  In other words, if your connected device is a PLC, when you set the bound 'temperature' property to 20.99, you are telling the PLC to set that tag to 20.99 as well.  I suspect that's why you're getting the error.  Instead of trying to modify that property value, perhaps create another property on your thing that represents the rounded values, or just round them off in a service before you return them to your mashup.

 

--Nick

View solution in original post

9 REPLIES 9
nmilleson
17-Peridot
(To:Sruthi)

@Sruthi ,

 

In your AnyDataChange service are you checking that there is a numeric value available for each of those?  I tried your code on some numeric properties in 9.1 and it worked fine.  Also:

 

1. Check the Application Log to see what errors there may be there.

2. Put a try/catch block on your code and then log the error

try {
   me.prop1 = me.prop1.toFixed(2);
   me.prop2 = me.prop2.toFixed(2);
   me.prop3  = me.prop3.toFixed(2); 
} catch (err) {
   logger.error(err);
}

 

Hope that helps!

Nick

Sruthi
14-Alexandrite
(To:nmilleson)

It is working fine when I try changing any property value manually and  without industrial thing connection. But, when I bind the source of the properties with the properties from industrial thing then it is not working.

nmilleson
17-Peridot
(To:Sruthi)

@Sruthi ,

 

If I understand correctly, you're trying to change the value of a property that is remotely bound to an Industrial Thing property?  Is that property supposed to be bi-directional in nature (i.e. are you able to change that property on whatever device it is bound to)?

Sruthi
14-Alexandrite
(To:nmilleson)

yes, your understanding is correct. It is connected to Industrial Thing. All the values are coming from Kepware to Thingworx. No values has been sent from Thingworx to kepware.

suverma
12-Amethyst
(To:Sruthi)

Hello @Sruthi,

 

Can you please share your complete Thingworx version.

Sruthi
14-Alexandrite
(To:suverma)

8.5
nmilleson
17-Peridot
(To:Sruthi)

@Sruthi ,

 

When you try and set a property value that is bound to an Industrial Thing (for example a PLC), ThingWorx will try and set that property ON the thing that is connected.  For example, if your device is sending a temperature value of 20.987654 to the property 'temperature' and then you try and change the property value 'temperature' to 20.99 in ThingWorx, you are asking it to set that temperature ON the device.  In other words, if your connected device is a PLC, when you set the bound 'temperature' property to 20.99, you are telling the PLC to set that tag to 20.99 as well.  I suspect that's why you're getting the error.  Instead of trying to modify that property value, perhaps create another property on your thing that represents the rounded values, or just round them off in a service before you return them to your mashup.

 

--Nick

Sruthi
14-Alexandrite
(To:nmilleson)

Oh, Thanks for the detailed explanation.

mgoel
17-Peridot
(To:Sruthi)

@Sruthi Can you check reply from @nmilleson on this thread. If that works for you please mark it accept as solutio for the benefit of other community users.

 

Regards,

Mohit

Top Tags