locked
CRM 2011 - Odata/Javascript - Setting Decimal Value on Creation of the record RRS feed

  • Question

  • Hi Forum,

    I am trying to create opportunity product record using Odata/Rest/Javscript in which I ma trying to set Quantity field which is of type decimal. (Mandatory field on OpportunityProduct entity form)

    I want to set the value as 1 and am using below syntex but it's throwing error.

    Error : "{\r\n\"error\": {\r\n\"code\": \"\", \"message\": {\r\n\"lang\": \"en-AU\", \"value\": \"Error processing request stream. Error encountered in converting the value from request payload for property \'Quantity\' to type \'Decimal\', which is the property\'s expected type. See inner exception for more detail.\"\r\n}\r\n}\r\n}"

    Code:

    var ObjOppProd = new Object();

    ObjOppProd.Quantity = 1.00000  // Setting quantity field.

    While debugging, ObjOppProd.Quantity gives me the value 1 instead of 1.00000

    and Xmlhttp response gives me above mentioned error.

    I have also tried : ObjOppProd.Quantity{Value : 1.00000} but with no luck and same appears.

    Any Ideas ???

    Thanks for your time

    H.Desai

    Wednesday, July 25, 2012 11:05 PM

Answers

  • Try:

    ObjOppProd.Quantity = (1).ToFixed(5);
    So you're essentially passing a string representation of the decimal, such that when it is turned into a JSON object, the decimal places are preserved.


    --pogo (pat) @ pogo69.wordpress.com


    • Edited by pogo69 Wednesday, July 25, 2012 11:13 PM
    • Marked as answer by H.Desai Thursday, July 26, 2012 5:50 AM
    Wednesday, July 25, 2012 11:13 PM

All replies

  • Try:

    ObjOppProd.Quantity = (1).ToFixed(5);
    So you're essentially passing a string representation of the decimal, such that when it is turned into a JSON object, the decimal places are preserved.


    --pogo (pat) @ pogo69.wordpress.com


    • Edited by pogo69 Wednesday, July 25, 2012 11:13 PM
    • Marked as answer by H.Desai Thursday, July 26, 2012 5:50 AM
    Wednesday, July 25, 2012 11:13 PM
  • Hi Pat,

    Thanks for this little tweak. 

    A very tiny change to this syntex worked !

      toFixed(5);  :)

    Cheers

    H.Desai


    • Edited by H.Desai Friday, July 27, 2012 1:35 AM
    Thursday, July 26, 2012 5:53 AM