Dynamics CRM Tip: Monetary Value in REST

Grey brick wall

I was running some JavaScript on a form and I wanted to populate a currency field with the value of another currency field. The source currency field existed on another record so I had to use the REST interface to retrieve this.

When I tried to populate the target field I received the following error -

"This control only accepts numerics or null as an input."


On debugging my JavaScript I found that the value of the source field returned by the REST request (in this case data.Price) was an object with property Value.


So, rather than set the value of the target field to data.Price I tried setting it to data.Price.Value. I received the same error.

On closer inspection of the Value property of the source object you see that it looks like a string rather than a decimal or float.

So I tried converting it to float using parseFloat() as I set the value of the target field.


This worked and the field was populated correctly.

So in conclusion, the value returned from a monetary field retrieved using the REST interface is an object which has a string property named Value. In order to use this value to populate another field it must first be converted to a float.

Hope this helps!

Hands typing on laptop with news

Join our Mailing List

Receive our latest technology news and updates straight to your inbox once a month. We will not share your data and you may unsubscribe at any time.