cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAI Format Number

lukas_schoeneberger70
Participant
0 Kudos

Hello experts,

I have a problem with a simple editing of a number.
From my API response I get various numbers with different decimal lengths. I save the value I need to the memory field "i". So I want to format it to round it to two decimal digits. The decimal seperator is a dot, which is fine for me.

My attemend looks like this:

{{formatNumber memory.i 2}}

Somehow it's not working.
Do you have any ideas?

Thanks in advance!

Regards,

Lukas

Accepted Solutions (0)

Answers (2)

Answers (2)

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

In what format are you getting the number? When I save let's say a requirement to memory, I need to use the raw property:

{{formatNumber memory.mynumber.raw 2}}
lukas_schoeneberger70
Participant
0 Kudos

Hi Daniel,
I recive it from an API, this is part of the answer:

 "item1List": {
        "contents": [
          {
            "ShortName": "Highlighter LUMINATOR Table 4-Set",
            "Price": 11.7,
            "Image": "pf00139596.jpg",
            "SupplierName": "Office Supplies"
          },
...
]}

I multiply the result (the price) by a number and save the value as "i". The number I'm getting earlier and it has the format you described (memory.quantity.scalar). So "i" should be the correct format.

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

Can you post a picture of how you store the value in i, and a picture of the memory after you store the value as i?

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

I set the values you described:

And the memory is set just fine:

erickgomez-tech
Participant
0 Kudos

Hi Daniel, If you let me ask I'll appreciate it!

How can I add format to API Response: {{api_service_response.default.body.value[0].NetSalesAmountLC_SUM}}

I'm using: {{formatNumber value decimalSeparator thousandSeparator}} but don't work, I have investigated a lot and have not found the same example that will serve me.

Many thanks for considering my request.

Erick Gómez

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

suggestum Can you give more information? What exactly is your code? What exactly is the value coming from the API? What error message do you get from the debugger?

Works for me:

erickgomez-tech
Participant
0 Kudos

Hi Daniel, thank you for your answer and support.

The response from the API (SAP Business One - Service Layer) is:

In my bot I can see:

My script is: {{api_service_response.default.body.CurrentAccountBalance}}

Now analyzing, I can see the problem: this value is a text format.

¿You agree with me?

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

If it works, that's great.

But for me, entering either of the following both work:

{{formatNumber "100.1234" 2}}

{{formatNumber 100.1234 2}}

dtephan
Participant
0 Kudos

Hi Lukas,

when you say it is somehow not working I assume that the message does not show up at all. For that you could use the "Chat Preview" to test the flow and open the "Debug View" by clicking on the button in the top right corner. There should be a warning message explaining what the actual issue is. For example it could be that memory.i contains a JSON structure that contains the number instead of the raw value which would look like this

"Helper parameter '{ confidence: 0.92, raw: '2.56478', scalar: 2.56478 }' is not a parsable number (error code: 'ScriptingEngine - 0120', id: 'xxx')."

Please make sure that the formatNumber helper is only receiving the raw number value.

Hope this helps and best regards,

Stephan

lukas_schoeneberger70
Participant
0 Kudos

Hi Stephan,

thanks for your quick response.
It is a valid number, I multiplied the memory before and it's working. I also checked the preview and the debug.
The item1Amount is also in embedded in a quick response and displayed, so it is saved to the memory but not formatted.

Regards, Lukas