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 :)

2 comments:

Anonymous said...

Hello Ronald,

I was having a problem in customising the order form in Microsoft CRM 3.0

I have 5 custom entities there on my order form havin a 1 to many relationship.
Now my problem is that when OI convert an order to invoice from the toolbar button I am not able tohave the custom entities m records in the created invoice form.

I am in a total mess & dontr know what to do...

Please help me out.

Regards,
Susan

Ronald Lemmen said...

Hi,

You would need to create the same relationships on the invoice entity. Then in the mapping between the order and invoice entities you would need to add the mapping between the attributes on the order to the invoice.

Hope this helps,

Ronald