Javascript to grab a field value and display in message box

If you want to grab a value of a field in a form in Microsoft CRM and display that value in message box to the user, here's how you can do it with Javascript:

CODE:

function DisplayValue()

{

var thismargin = new Xrm.Page.getAttribute("new_margin").getValue();

alert('Your margin is: ' + thismargin);

}

NOTE: the field you are grabbing ("new_margin" in the above example) is the name of the field in CRM (not the "display name" that you see on the form).

Tested with Microsoft CRM 2011 online version.