Showing posts with label rollup12. Show all posts
Showing posts with label rollup12. Show all posts

December 8, 2014

Retrieve the current CRM version

The CRM SDK DLLs can easily connect to different CRM versions, for example the CRM 2013 DLLs can be used also with CRM 2011/2015 environments.
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;
}

July 16, 2013

How to bind a function to the Sub-Grid refresh event

A common customization requested by customers is to execute some logic when a Sub-Grid is refreshed. Unfortunately the Xrm Object Model doesn't provide a method to bind a function to the refresh event.
To implement this functionality is necessary to use unsupported JavaScript code, paying attention when a new rollup is released.
The following code is compatible with UR12/Polaris update that introduced cross-browser support for CRM 2011.
function AddEventToGridRefresh(gridName, functionToCall) {
   // retrieve the subgrid
   var grid = document.getElementById(gridName);
   // if the subgrid still not available we try again after 1 second
   if (grid == null) {
       setTimeout(function () {AddEventToGridRefresh(gridName, functionToCall);}, 1000);
       return;
   }
   // add the function to the onRefresh event
   grid.control.add_onRefresh(functionToCall);
}
Is possible to use the AddEventToGridRefresh function in two different ways. Assuming to attach the following function:
// function used in this example
function AdviseUser() {
   alert("Sub-Grid refreshed");
}
The function can be called directly passing the parameters inside the dialog box


or inside another JavaScript function:
function OnLoad() {
   AddEventToGridRefresh('accountContactsGrid', AdviseUser);
}
The first parameter is a string and quotation marks are necessary, the second parameter is the name of the function and must be written without quotation marks.

April 16, 2013