Dynamics CRM 2013 - Convert String to Money. RRS feed

  • Question

  • HI all,

    I am creating a plugin and in the plugin i need to retrieve Revenue amount do some calculation and then put it in another currency text field.

    Below is the way I am doing it.

     //Get the Exchange Rate

    decExchangeRate = (Decimal)(a.Attributes["exchangerate"]);

    //Getting the VatAmount

    decVatAmmount = ((Money)(a.Attributes["new_vatamount"])).Value;

    //do some calculation

    decBaesVat = (decVatAmmount / decExchangeRate);

    //Place the calculated amount in a currency field on the form

    entProductLines.Attributes.Add("new_estvatamount", decBaesVat);

    Can anyone help me how to convert the decBaseVat and place it in the attribute?

    Many Thanks



    Thursday, November 21, 2013 11:06 AM

All replies

  • Hi Vinay,

    Money type has a constructor for decimal type, so you can do the following:

    entProductLines.Attributes.Add("new_estvatamount", new Money(decBaseVat));



    • Proposed as answer by Guido PreiteMVP Thursday, November 21, 2013 12:18 PM
    Thursday, November 21, 2013 12:07 PM
  • Hi Adam,

    I have tried it, it didnt work.

    Any other option?

    Thanks & Regards


    Tuesday, November 26, 2013 12:39 PM
  • Hi Vinay,

    Please make sure your plugin is registered on Pre stage. i.e. Pre-Operation / Pre - Validation.

    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
    Vikram Singh. !!!  My Blog

    Tuesday, November 26, 2013 12:45 PM
  • In what way does it 'not work' ? Does the code execute ? Does it throw an error and if so, what is the error ? What happens if you debug the code ?

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Tuesday, November 26, 2013 2:21 PM