Parsing a value which is more than 15 digits using javascript

Hi,

I am trying to parse a string that is more than 15 digits using Javascript. I see the max digits allowed in javascript is only 15. is there any other way to pasre it ?

the customerID is 18 digits and i need to retreive that from a payload and pass it along to service callout.

the last 3 digits are added as 000 if i use toString() or its getting converted to 1.e17 if i use it as number.

TIA

Aswin.

0 1 928
1 REPLY 1

Hi Aswin

I understand you are trying to "parse a string" and I am guessing that the string is an all numeric string, and that it is 18 digits. 18 digits of 0-9.

You want to "retrieve it from a payload and pass it along to a service callout".

You are seeing a representation like "1.e17". This tells me that the string is being converted somehow to a Number within the JS callout, and then re-converted from that number back into a String. Avoid this double-conversion and you wont see the 1.e17 output.

If you treat the string of digits that is the customerID as a string (and I think you should, it's a string, and not a number) , then there is no need to "parse" the thing as a number, or coerce it to become a Number type. If you don't try to coerce it to a Number, then there will be no 1.e17 representation.

For example, suppose this is the input payload:

{
  "customerId" : "12345678901234567890"
}

That long string is ... a string. To extract it into a context variable from within a JS callout, all I need to do is something like this.

var c = JSON.parse(context.getVariable('request.content'));
context.setVariable('extracted_value', c.customerId);

There is no "conversion" to a Number. Therefore the thing in the "extracted_value" context variable will be the original string.