Saturday, April 16, 2011

Javascript inconsistency with Xrm.Page model

While doing ribbon customization today I found an interesting issue with how the new Xrm.Page model introducted in CRM 2011.

I have a ribbon button which simply fires a javascript function:

function lookup_form() {
    alert(Xrm.Page.getAttribute("dc_openform").getValue());
    alert(crmForm.all.dc_openform.DataValue);
}

I would type a value into my dc_openform field, and click the ribbon button. The first alert would show what was *previously* in the field, while the second alert showed what is *currently* in the field. If I clicked off the field then click the button again, the values match up.

Thus, it appears the the Xrm.Page model is only updated onChange, and that onChange is not fired between typing into a field and clicking the Ribbon button.

Thursday, April 7, 2011

Odd Currency Symbols returned from FetchXML

While working with CRM2011 FetchXML, I came across a nasty issue when retrieving a currency field. I have done this successfully many times before, but for some reason this time I was getting multiple currency symbols in my raw XML result, ie:

$‎5,000

instead of the desired:

$5,000

Adding transactioncurrencyid to the fetch did not help, and replacing "$‎" with "$" directly also did not work. However, after toying about with the string in unicode for a bit, I came up with:

value = Regex.Replace(value, "\u200e", "");

This properly removed the funky symbols, leaving me with "$5,000". Likely something under the hood is causing an issue elsewhere, but this is a great workaround if you just need to get a properly formatted currency field without hacking deeper into the CRM platform.

Friday, April 1, 2011

No Calendar when Enabling DateTime fields via Javascript

I ran into an annoying problem today. I was enabling and disabling a DateTime field via Javascript via the following code:

Xrm.Page.getControl("new_datetimefield").setDisabled(true/false);

However, even when enabled, the calendar button did not function and I couldn't put any dates in the text box.

It turns out that this is a bug in CRM2011 - The fix is to ensure that the DateTime field is enabled by default on the form, then disable or enable via Javascript. If it is initially disabled, it will not be properly editable even when enabled via Javascript.