Tuesday, 20 April 2010

What’s with all the CRM?

In case you’re curious I have shifted teams at work and now I am working with Microsoft’s Dynamics. Specifically CRM at the moment. So for the last two weeks and for the next month and a half I am working with Microsoft CRM. And quite enjoying it too. 

Change is good!

Writing to a CRM date control from a child form

Despite the fairly innocuous title this issue had been bothering (driving me crazy) for most of the last day.
Problem:
The clients CRM Contact form has a button that uses JavaScript to launch an external web page (we’ll call it the child form). This form would perform a search and return a list of matching users. Each user would have a button and when you clicked a user’s button it would use JavaScript to populate the parent form’s (in this case the CRM contact form) fields such as address, gender, ethnicity and date of birth.

e.g. opener.document.crmForm.all.address1_line1.DataValue = [address text];
Now this worked fine for the text fields, and pick lists but when I tried to write to the date control it did not play nicely. Now to populate a date control in CRM using JavaScript you set the DataValue to a JavaScript date
e.g. opener.document.crmForm.all.birthdate.DataValue = new Date();
However when I called this code from the child form it would populate the CRM Contact Form’s date of birth control successfully but that’s as far as it got. It would then hang if I tried to close or save the form. It would say a CRM error occurred and it that it had to close the form.
However when I tried putting the exact same piece of code without the parent reference in the Contact form’s CRM load event
e.g. crmForm.all.birthdate.DataValue = new Date();
it would work fine. It would save or close the form with no problem. Awesome!! Nothing like inconsistent behaviour.

Solution:
My work colleague Steven Foster wins the chocolate fish for the “magic” workaround (I thought magic sounded better than dirty) that saved the day :)
The solution was to have a hidden text field on the CRM Contact form that the child form would write the date to as text e.g. “21/11/2009”. Fortunately the child form would always write the date in a consistent manner so I could rely on it being in the format “dd/MM/yyyy”. Then I called the hidden fields FireOnChange() event to trigger the CRM OnChanged event. I then added a CRM OnChanged event to the new hidden text field that would parse the string and convert it into a JavaScript date and use that date to populate the date of birth control.

The JavaScript code on the child form
opener.document.crmForm.all.[hidden text field].DataValue = [date of birth text];
opener.document.crmForm.all.[hidden text field].FireOnChange();

The JavaScript on the CRM Contact from hidden text field OnChange event
var textDate = crmForm.all.[hidden text field].DataValue;
var dateParts = textDate.split(“/”);

var birthdate = new Date();
birthdate.setDate(dateParts[0]);
birthdate.setMonth(dateParts[1]-1);
birthdate.setFullYear(dateParts[2]);

crmForm.all.birthdate.DataValue = birthdate;


So there you go problem solved!

Monday, 19 April 2010

How to migrate iTunes libraries

Surely this process should be easier…

Thursday, 15 April 2010

Do not develop CRM on a machine that you are also deploying into the GAC

I was getting a System.TypeLoadException as it couldn’t find the file i had just added in my project. Every time i ran my test against the project i kept getting the same result. Enter plenty of colourful language and head bashing.
Fortunately in my googling i came across this helpful explanation on StackOverflow. It turns out that if a version of the file exists in the GAC then it will use the GAC version (assuming the version number is the same) and not the version you think you are debugging. Thank god for Google but how did i get here?
I am currently on a Microsoft CRM project and i had to build a plugin (dll) and deploy it. The development environment is hosted by the client and is also the test environment. Anyway it turns out when you want to deploy two dlls as part of a plugin (for example the plugin dll and some domain or business logic layer dll) then you have to deploy the secondary dll (not the plugin) to the GAC so that it can be referenced… nuff said there really.

So the short version is try and avoid debugging projects that are in the GAC as well. I think Chandler from friends sums it up quite nicely “oh god, can open… worms everywhere”

Wednesday, 14 April 2010

MP3 store Comparison

It is very interesting to see who is putting in personal tracking details in the music they sell. As a bit of an Apple fan i am pretty disappointed