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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

[Services] Unable To Convert with ParseFloat()

Clement_D
10-Marble

[Services] Unable To Convert with ParseFloat()

I want to convert data that I receveid from arduino board via serial to float.
When I use ParseFloat on the service that I created on a Shape, i have the following error :

>Error executing service. Message ::Unable To Convert From org.mozilla.javascript.UniqueTag to NUMBER - See Script Error Log for more details.

 

I don't know where I can search to correct this. I only found who has to convert into infotable.
If someone know example of similar javascript service on thingworx that are working. It would be very useful for me.

In my service, Inputs are string and Output (result) is Number.

This is my code :

 

me.value1=parseFloat(value1);
me.value2=parseFloat(value2);
me.value3=parseFloat(value3);
me.value4=parseFloat(value4);
me.value5=parseFloat(value5);
me.value6=parseFloat(value6);
me.value7=parseFloat(value7);
me.value8=parseFloat(value8);
me.value9=parseFloat(value9);
me.value10=parseFloat(value10);
me.value11=parseFloat(value11);
me.value12=parseFloat(value12);

 

Thanks in advance for your help.

 

ACCEPTED SOLUTION

Accepted Solutions

The service ingesting the data, has Output defined? if that's the case, on your script code you have the corresponding : 

var result = something;

View solution in original post

5 REPLIES 5

The service ingesting the data, has Output defined? if that's the case, on your script code you have the corresponding : 

var result = something;

Thanks for your help, I thought I didn't need to use results because my service is only used to make conversion from string to float.

So i have add results with my 12 values. I have no longer the error but I thinks my syntaxe isn't good because only value1 is in black.
>var result = value1,value2,value3,value4,value5,value6,value7,value8,value9,value10,value11,value12 ;
(image link)

The service is now working as I want because I am able to send with POST method, value to simulate sensors and the value are update in my object thanks to the service. However it seems that to me that my results is weird and shouldn't work.

Is there a better way to code results ? I don't know what is the best practice.

Hi Clement,

 

parseFloat works in converting String to Number. But it appears from the error that your value is of type UniqueTag and not String. I would try converting it to String first and then convert it to number. Try this: 

me.value1=parseFloat(value1.toString());

Hope it helps.

 

Best regards,

Rajesh.

Thanks you for your help.

After adding results I try with and without your solutions and the results are the same no more uniqueTag error.

I don't know why it was unique tag error but it seems that it isn't link to the type I recevied because when I erase results i have the same uniqueTag error.

If you don't need the output of the service just set it as NOTHING and you will not need the var result = something.

Announcements


Top Tags