Depending the version some messages (like the ExecuteMultipleRequest) are not available, the following function returns an enumerator with the current CRM version.
public enum CRMVersion { Unknown, CRM2011, CRM2011UR12PLUS, CRM2013, CRM2013SP1, CRM2015 } public CRMVersion GetCRMVersion(IOrganizationService service) { RetrieveVersionRequest versionRequest = new RetrieveVersionRequest(); RetrieveVersionResponse versionResponse = (RetrieveVersionResponse)service.Execute(versionRequest); string version = versionResponse.Version; if (version.StartsWith("5")) { try { int buildNumber = Convert.ToInt32(version.Substring(version.LastIndexOf(".") + 1)); if (buildNumber > 3000) { return CRMVersion.CRM2011UR12PLUS; } } catch { } return CRMVersion.CRM2011; } if (version.StartsWith("6.0")) { return CRMVersion.CRM2013; } if (version.StartsWith("6.1")) { return CRMVersion.CRM2013SP1; } if (version.StartsWith("7")) { return CRMVersion.CRM2015; } return CRMVersion.Unknown; }
Wouldn't it be better to write it in such as way as to do feature detection, rather than version detection? For example, rather than asking "Is this CRM version before CRM 2011 Rollup 12?", wouldn't it be better to ask, "Does this CRM instance support ExeucteMultipleRequest?"? Or, "Does this CRM instance support Actions?", rather than "Is the CRM version before CRM 2013"?
ReplyDeletewill be nice, but lucky for us there aren't so many differences in the SDK calls between 2011/2013/2015. They kept consistent the platform (not as the CRM 4.0 to CRM 2011 migration), I did a quick check but looks like that the metadata doesn't contain a unique place for listing the messages/features supported. However the main purpose of my code is to prompt to the user "Wow! you are using {CRMVersion}, cool system you have there bro" :)
ReplyDelete