CRM 2011 - Set value of currency field with javascript

ThdK picture ThdK · Aug 24, 2011 · Viewed 21.1k times · Source

I really can't find how i can retrieve the value from a currency field and set it as a value for another currency field for another entity.

My following code is not working:

var entities = retrieveRecords("trainingSet?$filter=trainingId eq guid'" + GetLookUpData("trainingid").id + "'");
    if (entities != null) {
        if (entities.d.results.length > 0) {
            if (entities.d.results[0]["Price"] != null) {
                alert(entities.d.results[0]["Price"]);
                Xrm.Page.getAttribute("price").setValue(entities.d.results[0]["Price"].getValue());
                Xrm.Page.getAttribute("price").setSubmitMode("always");
            }

        }
    }

Error sais that the control only except numbers or null.

Any help would be really appreciated! Thanks!

Answer

Bryan Weaver picture Bryan Weaver · Aug 25, 2011

I have used this before even though I am not a fan of the eval.

function SetMoneyAttribute(value, attribute) {
                      Xrm.Page.getAttribute(attribute)
                    .setValue(parseFloat(eval(value)));
        }

here is a blog post about setting form fields with queried values.

http://crmscape.blogspot.com/2011/03/crm-2011-odata-json-and-crm-forms.html