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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

How to convert number to integer in JSON output of a service

MarcosI
2-Explorer

How to convert number to integer in JSON output of a service

Hi,

It's happening to me the same.

there is an AWS API that is expecting a value type "integer" but it seems it is getting a value type "number" so the validations are failing.

I tried to use parseInt(13) but it is still failing. It seems Thingworx is sending this vaule as number instead of integer...

var body= {

"productionCenterID": parseInt(0),
"labelSize": parseInt(8),

}

and this body is used in Resources["ContentLoaderFunctions"].PostJSON

 

Any idea?

3 REPLIES 3
Ashritha
15-Moonstone
(To:MarcosI)

Hi,

 

If  floating part of number has to be removed, then following method can be used.

let num=10.0;
result=num.toFixed();

 

Hope this helps!!

 

 

MarcosI
2-Explorer
(To:Ashritha)

Not sure if this is related with my issue. I need to send and integer and .toFixed() is creating an string. Probably there is no solution as javascript data types does not understand integers or floats, all are all numbers.

Ashritha
15-Moonstone
(To:MarcosI)

Hi,

 

There can be work around for this issue:

  • Create simple service : ConvertNumberToInteger
  • Create Input : num  -> NUMBER (baseType)
  • Output : INTEGER (baseType)
  • Code : 
    let result = num;​

Whenever conversion required, this service can be called.

 

Hope this helps!!

 

 

Announcements


Top Tags