Community Tip - You can change your system assigned username to something more personal in your community settings. X
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
Solved! Go to Solution.
@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 ,
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
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.
@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)?
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.
@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
Oh, Thanks for the detailed explanation.
@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