Skip to main content
10-Marble
June 27, 2019
Solved

[Services] Unable To Convert with ParseFloat()

  • June 27, 2019
  • 2 replies
  • 3230 views

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.

 

Best answer by CarlesColl

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

var result = something;

2 replies

1-Visitor
June 27, 2019

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

var result = something;
Clement_D10-MarbleAuthor
10-Marble
June 27, 2019

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.

5-Regular Member
June 27, 2019

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.

Clement_D10-MarbleAuthor
10-Marble
June 27, 2019

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.

1-Visitor
June 27, 2019

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