Friday, May 08, 2009

Enhancing performance in virtual machines

I follow the blog Microsoft Dynamics CRM UK Blog which is very good and they had an interesting posting today concerning performance issues in virtual PC 2007 on laptops. As most consultants, I use one (a lenovo T61p). You can read more about it here: http://blogs.msdn.com/ukcrm/archive/2009/05/07/virtual-pc-2007-performance-tweaks.aspx

When I tried to apply the change to the file they mentioned (%appdata%\Microsoft\Virtual PC\options.xml) I had a problem since I didn't have the parent tag in my file. I checked around a bit and found that it could just be added to the main structure. So, after modifications, my file looked like this:

----
</virtual_network>
<virtual_machines>
<enable_idle_thread type="boolean">true</enable_idle_thread>
</virtual_machines>
<window>
---

I would recommend adding it, if you most of the time have the computer connected to the power outlet, since it will probably increase the performance of your virtual machines!

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Monday, April 20, 2009

Importing large customization files to vanilla system

Sometimes you will need to import large customization files from one system to a vanilla system (no customizations). This file will often include workflows as well as new entities and attributes.

Since the workflows are dependant on the entities of the CRM system, a workflow cannot be imported if the entities it depends on do not exist.

This is usually not a problem in English based systems since Workflow starts with the letter "W" and hence is quite far down the list. In Swedish it is named "Arbetsflöde" and hence will be placed at the top. So, when importing the customization file, if importing everything, the system might give you an error if any workflow is dependant on an entitiy with a displayname after "A".

The solution is simple, just import everything but workflows first and then import workflows.

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Monday, February 23, 2009

Errors when programmatically attaching events in forms

Today I had a very weird error. I had two datetime fields on a form, one on the first tab and one one the second. Let's call them date1 and date2 to make it easier.

I attached an event in the onload by using

crmForm.all.date1.attachEvent("onchange", myFunc1);

and for the date2 field:

crmForm.all.date2.attachEvent("onchange", myFunc2);

The weird part was that if I changed date1 first and then date2, myFunc2 didn't fire. But if I first changed date2 and then date1, both fired as they should.

So I tried just adding an alert instead using the normal onchange method via the form editor in CRM and that triggered every time, just as it should, so something is different.

The simple solution seemed to be to move date2 from the second tab to the first. That got everything working just as it should.

I havn't tried it but I think that one could also write a method that confirms all the event attachments and then calling this at the end of every onchange triggering function and perhaps some extra time when the tabs are changed to make sure the events are bound correctly.

I have checked the documentation in CRM for if this kind of runtime event attachment might not be supported but my interpretation of the text is that is should be all right according to it. The closest paragraph in the unsupported customization section is the following:

"The use of custom HttpModules to inject HTML/DHTML into the Microsoft Dynamics CRM Forms. "

As I wrote, my interpretation is that attaching events (not even overwriting the onchange), should be ok according to this since we arn't injecting anything, just adding an event listener. Hence I feel that this must be interpreted as a bugg in CRM.

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Tuesday, February 17, 2009

Unicode conversion

When writing javascripts with alerts or similar when not working with english, special characters like the swedish åäö might not be shown correctly. I found this helpful page where you can enter the string you want to convert and then copy paste the result. Simple and nice.

http://rishida.net/scripts/uniview/conversion.php

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Really cool way of getting FetchXML from advanced find

I've been having some problems with my blogs in Outlook but today I fixed it and started checked if there was anything special and found this very interesting article on Ronald Lemmens blog.
http://ronaldlemmen.blogspot.com/2009/02/using-advanced-find-for-fetchxml.html

He describes how to, without any code or customizations to a system, easily get the fetchxml code from an advanced find by just putting some javascriptcode in the url of the window. Beautiful in all it simplicity!


Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Force update of Report

The project I am currently involved in uses Reporting Services reports that are shown as PDF:s as quotes that are sent to the customer. It is implemented by creating a custom report that takes the object id (like quote) which is called from an isv.config button and by using querystring parameters, the output is directed to PDF.

However, I got a puzzeling bug. The data in the quote is of course based on data in some CRM entities and when a quote was generated and the user found something was wrong, changed this in CRM, saved and then tried to regenerate the PDF, the change didn't show. I restared Internet Explorer, and regenerated the quote-pdf and now it showed correctly. Hence some sort of caching error.

I looked around the internet a bit and found that by adding the following parameter to the querystring, I could refresh the sessions variables and I would get a fresh and correct report.´

&rs:ClearSession=true

So, the entire url was (except for the report id etc.):

&rs:Command=Render&rs:ClearSession=true&objid={D1F1FD5D-D7F8-DD11-967B-005056AA29F5}&rs:Format=PDF

So, if you get a similar error, just try setting this.

It is also possible that IE caches the pdf and then you'll have to add some variable to the querystring, like a tick or datetime that is unique for every call (from that client) and that will bypass IE:s caching.

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Tuesday, February 03, 2009

Workflow warning

Today I was troubleshooting a CRM server which had the CRMAsycnService and w3wp service totally hogging the machine. It was quite obvious that it was CRM that was the cause for this and since CRMAsyncService was involved, probably workflows or perhaps the deletionservice.

After a bit of looking around I found a workflow that was set to trigger on attribute change on an entity and then later in that same entity, changed some attributes. This caused an infinite loop which was the cause for the hogging. By first unpublishing the workflow and then removing all started systemjobs, I got the machine back up to speed.

My conclusion from this is that even though the workflow GUI seems easy it is deceitfully powerfull and you quite easily create workflows that hogg the server (the server hosting the async-service anyway). This should be taken into consideration when putting this tool into the hands of non-programmers since the risk for the entire system stability is large. This can be either application consultants or power users at the customer.

There is also no standard way of locking some of the triggers on workflows so that you can eliminate this risk. I you know of any, please leave a comment!


Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Monday, February 02, 2009

Process implementation strategy

When implementing a business process in Dynamics CRM there are several different implementation paths to choose from. There are advantages and disadvantages to the different techniques but there are some goals that I feel the implementations should meet, mainly:



1. Fully supported customizations only

2. Flexible and non-static.

3. Power user modifiable

4. Movable from environment to environment (dev-test-production)



I will discuss the different aspects bellow and why I feel they are important.



Fully supported customizations only

This is almost so self-evident that it doesn't even need mentioning but I have seen several CRM implementations that not only nudge this paradigm in the corner, but bite big large chunks out of it. For me, the number one reason why this is so important is that all customers will sooner or later want a hotfix or upgrade to a later version and when Microsoft, in their greatest foresight and benevolence definied the concept of supported customizations, they made this possible without costly maintanance agreements or hostile customer relationships. So, not following it should be punishable by death or something close to it.



I would presume that you CRM implementations are meant to last for your customers and that you want a long a fruitfull relationship with your customer, why you just cannot underestimate this point. If you have to make unsupported customizations, make sure they are as light weight as possible, document them thouroghly and how to validate them when installing a hotfix or upgrade.



A business process must hence be made as supported as possible.



Flexible and non-static

The solution has to be flexible and non-static. We, and our customers live in an ever changing world and to cope with this, business processes have to change as the world around a company changes. Just imagine the changes the telecom industry has gone through the latest 20 years. To fully accomodate this the customer implementations have to be flexible and changable. Microsoft Dynamics CRM is one of the most versatile and flexible systems available, especially now that it incorporates windows workflow foundation. Implementing a business process in code entirly, locks the processes down, and builds a dependance on the CRM delivering partner, something every customer-value focused consultant must despise. I do not need to force my customers to use my services when I can get them to choose me because of the value I deliver to them every hour of every day.



Instead, use the power of Windows Workflow Foundation combined with custom workflow activities. If needed, trigger these workflows using plug-ins and isv.config customizations.



Power user modifiable

A business process often involves users of different sorts and communicates with these using emails, tasks and other activites. The content of these and the recipients, sometimes dynamically set, sometimes static (like the CFO), might need to be changed. Therefore it is not very flexible for the customer if code has to be re-written everytime a mail has to be changed. It is a lot more flexible to create a workflow that creates the activity and then just execute the workflow from code, apart from the fact that it is a lot quicker to implement. Just write a method that enables you to execute the workflow by name instead of Guid.



Movable from environment to environment (dev-test-production)

All implementations of any notable size always includes at least three environements, not seldom up to 5 or 6 depending on how you count (local dev, central dev, test, training, production). Business process implementations have to be easy to move between solutions without any or with as little as possible environement specifics. Hence, try to use names (or some other environment indpendant value) instead of guids since guids are environment specifics when relating to workflows and other similar things. Try to get all environement specific settings in one place, one file or create an entity for them. This can be a challange but try, it will pay off in the long run.


These are my thoughts on the business processes implementation stategy concerning Dynamics CRM 4. I would be happy to discuss the topic so please leave comments!

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Thursday, January 29, 2009

Problem opening workflows in CRM GUI

Currently I am working on a project with a quite complex sales process and part of it is managed by workflows (for flexibility) and to be able to do what is needed, I have developed several custom workflow activities.

However, today I had just installed some stuff and was going to review one of the workflows, and the CRM GUI crashed with the Exception "System.NullReferenceException" in a really nasty way when I tried to open it. By looking at the stack trace I got a feeling it had something to do with my custom activities so I just reregistered them and then everything started working again. So if you come across this error, this might be the problem. I couldn't find any reference to this error on the net why I thought it might be a good idea to blog about it.

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Wednesday, January 28, 2009

Workflow activity development and file locking

As some of you might have noticed, the dll:s containing the custom workflow activities might get locked and hence the compilation fails in it's final stage.

To handle this, I tried a good program called Unlocker 1.8.7 which you can find here: http://ccollomb.free.fr/unlocker/ - it is freeware and it will tell you which processes are locking a file and can help you kill them.

So, what is locking my dll? Well, actually several processes are involved both the MSCRMAsyncService and the IIS worker process (w3wp).

The most obvious way of handling it is just restarting the two services and that will work. However, restarting the w3wp process will require the entire CRM application to be recompiled which will create extra long and annoying waits. Instead, just recycle the applicationpool involved (CRMAppPool).

There are no problems restarting the MSCRMAsyncService.

And if you want to do it all in the pre-build event just add the following lines:

net stop "MSCRMAsyncService"
net start "MSCRMAsyncService"
cscript C:\Inetpub\AdminScripts\adsutil.vbs stop_server W3svc/AppPools/CRMAppPool cscript C:\Inetpub\AdminScripts\adsutil.vbs start_server W3svc/AppPools/CRMAppPool

And if you are still having problems, use the unlocker program!

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Tuesday, January 13, 2009

List Web Part for Dynamics CRM 4.0

Finally Microsoft have release the List Web Part for Dynamics CRM 4.0. I havn't had the opportunity to test it yet but the previous version (for CRM 3) had problems with non-english versions of SharePoint so be aware, especially if you are running CRM and SharePoint in different base languages.

If you have any experience of it, please let me know.

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Thursday, December 18, 2008

How to make a workflow wait until a certain date

How to make a workflow wait until a certain date might seem trivial but it isn't all that clear when using the GUI, but I found a nice blog with good pictures explaining how to do it so instead of reinventing the wheel, I'll just give you the link: http://www.askcrm.com/Default.aspx?tabid=866&EntryID=55

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Sunday, November 23, 2008

AT&T Wireless self destructs...

It's actually an old story by now but I just recently heard of it from my new staff manager and it is a very interesting story of just how bad a CRM implementation can get. It concerns Siebel and my analysis of the story is that the reson for the crash was mostly due to bad management and a lock on both timeframe and functionallity, something I believe is impossible if you want to achieve any kind of quality. This case being the perfect example.

Please read it and leave a comment here if you want to discuss it!
http://www.cio.com/article/32228/Project_Management_AT_T_Wireless_Self_Destructs

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Wednesday, November 19, 2008

Automatic restart of Async Service

When developing new workflow activities for CRM 4.0 you need to release the filelocks on the dll to be able to copy the new dll to the assembly directory. This can of course be done manually by restarting the service in the service manager but can be scripted into the prebuild events aswell, so that it is more automatic. Add the following two lines to the Pre-build events of your workflow activity project to make it restart the MSCRMAsyncService:

net stop "MSCRMAsyncService"
net start "MSCRMAsyncService"

Please note that you might inflict any ongoing workflows by doing this so take care if it is a live production server.

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Friday, November 14, 2008

Quick create

As many of you know, in CRM 3 there is a special view of an entity form called quickcreate. This is used when you press "New" in a lookup window. For instance, on an account you can press: select primary contact, when the search dialog shows you can instead of selecting an existing contact press the new button and a "slimline" version of the contact form show with just the must-have and should-have fields available.

In CRM 4 this feature is not used any more and the complete form will always be shown in this case, however, the functionality hasn't been removed. I tried to find some kind of reference to it in the SDK but couldn't so I had a look in the original CRM code in CRM 3 and found how to do it.

To open a form as quick create, find the object type code (1 = account etc) and go to the URL:
http://[server:port]/[organisation]/_forms/QuickCreateReturn/quickcreate.aspx?crmFormSubmitObjectType=[objecttypecode].

For example, for account on the local machine when CRM is installed on port 5555 and the company is named "company":
http://localhost:5555/company/_forms/QuickCreateReturn/quickcreate.aspx?crmFormSubmitObjectType=1

Since I couldn't find any official reference to this in the SDK it is very possibly unsupported to do this but it works for now. Any hotfixes or similar might, but are not very likely to change this functionality, new versions of CRM like v.next are more likely to change/remove this functionality.

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Tuesday, November 11, 2008

Putting all javascript code in external files

Dynamics CRM is great. It has some really nice functions like being able to add javascripts to different event in the form to handle special needs of the GUI.

However, it is only fine as long as these scripts arn't that many and not too complex. When they start getting more and more complex, bigger and their numbers start increasing it soon becomes an impossible tast of maintaining them all and there is no built in function to handle javascript includes without special code. It also takes a long time developing more complex code in the javascript form window in CRM and then running the preview or publishing it each time before testing.

There is light in the tunnel however, by using the technique specified bellow, you can both
get global javascript files, save and refresh only to see you changes, and keeping all scripts for one entity in one file (and not one for onLoad, one for onSave and one for each onChange that is needed).

A lot of credit for this has to go to Michael Höhne at Stunnware since he added a posting on his blog on how to manage javascript includes in runtime.

So, first of all we have to put some standard code in the onLoad. This should only be done once and it shouldn't really be changed until you need to publish it for release (switching of the caching).

var LoadFile = function(url, cache)
{
var httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
httpRequest.open("GET", url, false);
if (!cache)

{
httpRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
}

httpRequest.send(null);
return httpRequest.responseText;
}

eval(LoadFile("/isv/mycrmext/javascripts/MyGlobal.js", false));
eval(LoadFile("/isv/mycrmext/javascripts/Account_onload.js", false));

This code simply loads and executes the two files MyGlobal.js and Account_onload.js located in the directory C:\Program Files\Microsoft Dynamics CRM\CRMWeb\ISV\myCRMEXT\JavaScripts
and can be found at the url: :port/isv/mycrmext/javascripts/">http://:port/isv/mycrmext/javascripts/.

So, copy-paste it into the onload event form in the account form editor in CRM. Activate the event, save and publish.

Then you can create the two .js-files at the specified directory. Start with just some test code like:
alert("This is the MyGlobal.js-file");
or something similar.

The next step is to try to avoid using the onsave and onchange events. This is quite easy when you know how but it is sort of in the gray area of supported customizations so be aware of this.

In the file Account_onload.js add the following code:
var MyOnSave = function()
{
alert("onSave");
}

var MyOnChange = function()
{
alert("onChange");
}


alert("onload)

crmForm.attachEvent("onsave", MyOnSave);
crmForm.all.name("onchange", MyOnChange);

This attaches a simple function to the onsave event of the form and another to the onchange event of the attribute "name".

The functional defintions/declarations can be put into any of the includefiles.

Now, just save the file, and open an account to see the magic! (It should show a dialog when loading with the text "onload", when the accountname is changed, it should show "onchange" and when saved, it should show "onsave".

Please note that I would advise you to put the javascript files in the same "host" from a IE perspective since you will get less problems with cross domain scripting and similar IE related security issues. This doesn't however mean that you cannot put the js-files anywhere on the internet where the clients can access it.

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Wednesday, November 05, 2008

How to get the URL to the reportserver programmatically

I was searching the net the other day to try to find a way to programmatically get the reporting server url from CRM. I thought that there must be some way to find it using the standard CRM webservice and I really looked throught the SDK and all the blogs I could find to see if anyone knew.



Finally I gave up and tried to find some other way to get it and I remembered that it is set in the registry so I wrote some code to get it from there and here it is in all it's simple glory:



RegistryKey regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\MSCRM");
string reportserver = regkey.GetValue("SQLRSServerURL").ToString();




And it worked but only just since it uses the server name and my VPN connection to the customers environment didn't bother with sending it to me why I have to manually add it to the hosts file.



The host file can be found at the path: C:\WINDOWS\system32\drivers\etc\hosts



and I added the row:

192.168.0.100 CRMTESTSRV



Now my button which point to my aspx that redirects to a the report in pdf-format works just fine and is independant of the CRM server it is installed on.



The solution isn't supported as far as I know since you never know if they might change the registry value in the future (not very likely in an update but might happen in an upgrade). If anyone has any supported way of getting this URL, please comment this post.



This could also be done using javascripts but I find it easier to manage server side code and it doesn't add that much overhead considering the report has to be generated independantly of if I use aspx or javascript to open the report.



Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Sunday, October 26, 2008

Attribute problems

As I have described earlier, a controlled and consistent handling of the customization file is very important in order to maintain coherent and properly mirrored systems.

As I am reading the book "CRM as a rapid devleopment platform" by David Yack at the moment, I will probably be commenting a bit on some of it's content. Even though I might not fully agree to all that is said in the book, I must really give it my best recommendations since it is really a good tool and has a lot of very useful tips and code libraries that can be used.

One of the things Yack treats in the book is the how to import and export customizations and his recommendation is to take as few entities as possible. My personal view is still that the best way to maintain "mirrored" systems and avoid any problems when importing, is to almost always move the entire set of customizations (using the import/export all entities) since I believe that will reduce the risk of anything bad happening and that the systems might accedentally not be the same until someone notices that an entity hasn't been moved from one system to another. Yack's manner of handling this is not directly wrong in my opinion, and it might work well but there might be need for more extensive documentation of exactly what customizations exist in all the different systems (for those who didn't read that posting, most commonly: Production, Test, Central Dev, Educational and Distributed VPC Devs)

A similar problem that might give rise to some headaches is that you might have seen to it that all systems have the same customizations and then notice that some attribute might have the wrong data type, and since you can't just change the datatype, you remove it and then recreate it using the same name as before. Now you try to export and import this entity to some other system, it will crash due to the fact that CRM will try to append the changes made but it doesn't log that you have removed the attribute and will just export an image of the exisitng system. When importing, it will try to find any changes and add these. When it find's a missmatch in the datatype of the entity in question, it will simply stop the importing.

So, try not to change attributes or entities this way. If you have created an attribute with the wrong datatype, remove it and create the new one with another name.

It is probably also possible to first remove the attribute, export the customization and import it to ALL system and then add the attribute, export and import it to all systems. Then you might get it to work but it's easy to miss one development VPC system and then you'll have to remove the attribute(s) by hand and that just isn't very good since these kinds of changes should be limitied to the customization master system.

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

The application platform on which CRM has been built

Some dicussion has been ongoing on wheter the application platform on which Dynamics CRM has been built will be used for other purposes, most noticable has probably been David Yacks book that I have discussed previously, that focuses more on this platform than on Dynamics CRM.

Today, since it is Sunday and I have some "free time" I took the opportunity to read The CRM Teams Statement of Direction and I found a very interesting part in the end that give a very direct statement on how Microsoft views this:

"Thus the underlying technology platform becomes an application engine to run a whole range of business applications. Microsoft Dynamics CRM simply becomes one business application that is run on the application platform."

So, perhaps we have put our card on the right horse this time (compared to Lehman and Brothers investors) since the future might show that experience in CRM development isn't only going to be a great asset when working with CRM but also a great asset since it will allow us to have a good heads start on the application platform, and the new applications that will be built ontop of it.

Discussions has also been around what is going to happen with NAV and AX. This is mere speculation, but it might just be that theses applications are the first to be migrated to the new application platform. So, get you MPC (Material and Production Control) books out and dig into ERP since that might just be the right skill to have.

If you havn't noticed, the work name for the new version of CRM is V.Next. Let's see if it will be 5.0 or perhaps 8.0? :)

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica
www.logica.com

Sunday, October 19, 2008

CRM as a Rapid Development platform

David Yack, a Microsoft MVP has written a very good book for developers working with Microsoft Dynamics CRM 4.0 independantly of the actual solution, being CRM or some other solution.

He focuses a lot on viewing the Dynamics CRM platform as a development platform instead of just an application with a powerful API. This is a view I believe many Dynamics CRM developers share with him. The book also focuses a lot on working as a consultant and the choices that one needs to take when working as a consultant, like, is this sort of solution going to be working independantly of new hotfixes, patches and upgrades or are we going to create a cause for conflict with our customer.

As many of you know, Dynamics CRM addresses these issues as a platform in the definition of "supported" customizations and this is discussed throughout the book.

Included in the price of the book is also an entire library of useful tools that can be used when developing and that Yack recommends using in real life projects and that are licenced as such.

It is THE book for all Dynamics CRM developers looking for both tips and tricks on how to for instance, actually create a plug-in and also great use in understanding that Dynamics can be used as a platform for developing almost any kind of application. Yack has deliberatly left out information concerning how to use CRM out-of-the-box and other normal application based aspects of Dynamics CRM, something I find very good since it focuses the book on what it is meant to do.

If you work with development in Dynamics CRM, this is probably going to be one of the best investments you can do, since it will help you create better customizations faster with more customer value, and who doesn't want that?

Thanks David Yack for a great book!

Read more here: http://www.thecrmbook.com

Gustaf Westerlund
Microsoft Dynamics CRM Architect

Logica Sweden
www.logica.com