Creating Environment independent solutions

When developing a solution for CRM, make sure that it runs on all different crm environments. Many implementations have their CRM installation on another port compared to the development environments. A way to handle this, is to look at the location of MS CRM as it is stored in the registery.


// Set default values
private const string CRM_REG_DIRECTORY = @"software\Microsoft\mscrm\";
private const string CRM_SERVICE_PATH = @"/2006/crmservice.asmx";

// Create CrmService instance
service = new CrmService();
service.Url = GetCRMWebServiceRoot() + CRM_SERVICE_PATH;

/// <summary>
/// Returns the recorded web location from the registry
/// </summary>
private static string GetCRMWebServiceRoot()
{
string result = null;
try
{
RegistryKey regKey = Registry.LocalMachine.OpenSubKey(CRM_REG_DIRECTORY, false);
if (regKey != null)
{
result = (string) regKey.GetValue("ServerUrl");
}
else
{
throw new ApplicationException("Microsoft CRM could not be found on this computer.");
}
}
catch (Exception err)
{
throw new ApplicationException("Cannot retrieve registry value for CRM web service. " + err.Message);
}
return result;
}


Thanks to Richard McCormick for providing the codes :)



Change requirement level at runtime

I've made quite some posts around how to dynamically modify the form by using JavaScript. One thing I haven't posted around yet, but what I do use quite often, is to modify the requirement level of attributes on the form at runtime. Based on a selection in the system, another field could become required. Also if the selection changes again, then the field should not be required anymore. Here is the code for making a field optional, recommended or required:


// Set field to not required
crmForm.SetFieldReqLevel("fieldname", 0);

// Set field to business required
crmForm.SetFieldReqLevel("fieldname", 1);

// Set field to business recommended
crmForm.SetFieldReqLevel("fieldname", 2);


Update: new code placed based on the comment by Peter. Before the update I had this piece of code:


// set the field required (i.e. show error message when field is not filled in)
crmForm.all.fieldname.req = 2;

// modify the label to be red
crmForm.all.fieldname_c.className = 'req';



Expert on Avanade.com

Avanade has create a profile for me on their public website in the experts section. It's quite a honer to be listed within the same list as Matt Joe, Dennis Mulder and Matt Parks. http://www.avanade.com/people/expert_detail.aspx?expertid=98

If you want to become an Avanade expert as well, feel free to contact me (ronaldl at avanade dot com) and I'll make sure that you get in contact with the correct HR person.



Reawarded MVP

Hi Guys,

As a reward for community work last year, Microsoft has reawarded me the Microsoft CRM MVP!

My community work includes:
- Around 1000 newsgroup and forum posts.
- Around 75 blog posts, of which 35 self written articles. The blog had more than 75k visitors.
- Writing the article "Many to many relationships" for the CRM Team blog and the article "The power of choice" for CRN.
- Working as 'Ask the Expert' at the Convergence both in San Diego and Munich.
- Other tasks like participating in the Titan beta, answering hunderds of direct mails and delivering product team feedback.

This year again I plan on continuing my community work. Also, if you see a question somewhere and you have the answer? Please take the time to answer the question and help this person out. We all started with questions, including myself, and helping people with your knowledge is one of the greatest things you can do. And one day you might even get awarded an MVP award as well :)

See you in the community!



New reasons added for why your callout won't work

The last weeks I've been adding multiple possible reasons with possible solutions to the checklist as published earlier. If your callout is not working, then make sure you view this list.

Happy coding!



Change username of user in CRM

Microsoft has released KB article #935220 some time ago. This article describes how to change the username of a user in Dynamics CRM. See the article here:
How to change the user name and the logon name for a user record in Microsoft Dynamics CRM 3.0

This worked for me, I hope this also might help one of you!



Add New Button on Lookup

Hi Guys,

I’ve been looking into how to enable the ‘new’ button on custom entities. Here is what I have found. O yeah, For the direct solution scroll to the end of the mail.

- You can set test some things when using this url:
http://localhost:5555/_controls/lookup/lookupsingle.aspx?class=null&objecttypes=10001&browse=0&DefaultType=0&ShowNewButton=1&ShowPropButton=1
Ofcourse modify the servername and the objecttypes to match your situation

- The properties and new button can be set by using the querystring parameters as given above.

- There is one additional piece of hard coding in the class Microsoft.Crm.Web.Controls.Lookup.LookupPageBase. This particular piece of code is this:


if (this._showNewButton)
{
for (int j = 0; j < this._objectTypes.Length; j++)
{
switch (int.Parse(this._objectTypes[j], CultureInfo.InvariantCulture))
{
case 1:
this._canCreateAccount = base.CurrentUser.GetPrivilege(Privileges.CreateAccount);
break;

case 2:
this._canCreateContact = base.CurrentUser.GetPrivilege(Privileges.CreateContact);
break;

case 3:
this._canCreateOpportunity = base.CurrentUser.GetPrivilege(Privileges.CreateOpportunity);
break;

case 4:
this._canCreateLead = base.CurrentUser.GetPrivilege(Privileges.CreateLead);
break;

case 0x10cc:
this._canCreateList = base.CurrentUser.GetPrivilege(Privileges.CreateList);
break;
}
}
this._showNewButton = ((this._canCreateAccount || this._canCreateContact) || (this._canCreateLead || this._canCreateOpportunity)) || this._canCreateList;
}

What it does, is looking to the specified list of objecttypecodes and looks if any of these match the id of account, contact, lead, opportunity or (marketing)list. If it does not match one of those, then the new button is hidden.

- You can run the javascript code "createNew();”. This is the same function as that will be executed by the button. Running this javascript will open the quickcreate window which will work.

- You can also modify the file ‘lookupsingle.aspx’. In this file there is the function window.onload() function. Modify this function to add these lines to the end:

//enable new button
btnNew.style.display = 'inline';

This will cause the new button to be visible.

That’s about it. Just add the line above and you’ll be ready to go. The new button will now be available for all entities. I haven’t tested this through so that will need to be done in your situation. Also note that this is unsupported and will not be migrated to a potential upgrade to titan or might be lost after an install of a hotfix.

Hope this helps,

Ronald