Tuesday, 7 April 2015

Top New Features in CRM 2015


1. Enhanced Business Processes
2. Enhanced Business Rules
3. Security Enhancement
4. Search
5. SLA Enhancement
6. Product Enhancement
7. Calculated and Rollup fields
8. Hierarchy Visualization

You will see the details for each features in my next posts.

Bulk Record deletion in CRM

You may need to delete record in the bunch of 350 records at a time to delete them rather them deleting one by one. Below is the code which is deleting System Jobs of the bunch of 350.

    List<Guid> lstAsynId = _context.AsyncOperationSet.Where(p => p.OperationType.Value == 10 && p.ErrorCode != null).Select(p => p.Id).ToList<Guid>();

        long Total = 0;

        ExecuteMultipleRequest bulkreq = new ExecuteMultipleRequest()

        {

            Settings = new Microsoft.Xrm.Sdk.ExecuteMultipleSettings()

            {

                ContinueOnError = true,

                ReturnResponses = false

            },

            Requests = new Microsoft.Xrm.Sdk.OrganizationRequestCollection()

        };


        int flag = 0;

        int batchsize = 350; //define the number of records for deletion


        foreach (Guid asyncId in lstAsynId)
        {

            if (flag < batchsize)
            {

                bulkreq.Requests.Add(new DeleteRequest()

                {

                    Target = new Microsoft.Xrm.Sdk.EntityReference(AsyncOperation.EntityLogicalName, asyncId)

                });

                flag++;

            }


            if (flag == batchsize)
            {

                _service.Execute(bulkreq);

                bulkreq.Requests = new Microsoft.Xrm.Sdk.OrganizationRequestCollection();

                flag = 0;

            }

            //service.Delete("activitymimeattachment", Attachment.ID);

        }

        _service.Execute(bulkreq);

    }

Pass parameter of lookup in openEntityForm using javascript


For simple lookup :

function OpenNewContact() {
 var parameters = {};
 parameters["new_accountid"] = "2878282E-94D6-E111-9B1D-00155D9D700B";
 parameters["new_accountname"] = "Contoso";
 // Open the window.
 Xrm.Utility.openEntityForm("contact", null, parameters);
}

For Customer or owner Lookup

function OpenNewContact() {
 var parameters = {};
 parameters["parentcustomerid"] = "2878282E-94D6-E111-9B1D-00155D9D700B";
 parameters["parentcustomeridname"] = "Contoso";
 // Open the window.
 Xrm.Utility.openEntityForm("contact", null, parameters);
}

Party List Parameter : We cannot pass parameters to Party list.

Open a Pre-populated child Record in CRM using Javascript


In 1:N relationship,sometimes you need to opea a child record by pre filled value(from the mapping). The below script will be used to do it.

var parameters = {};
var childEntityName=”contact”;

//Provide parent record guid

parameters["_CreateFromId"] = "08A03761-0996-E311-BC31-00155D000807″;

//Provide parent record entity type code

parameters["_CreateFromType"] = "1″;

//provide child entity name and pass parameter to open new record

Xrm.Utility.openEntityForm(childEntityName, null, parameters);

Parameters:

• _CreateFromId: Pass parent entity record’s GUID

• _CreateFromType: Pass parent entity type code

• childEntityName: Child entity name which need to open with mapping field

With this above code, you can add a custom button to simulate the + button on the child subgrids.

Check whether User has specific role or not


The below code will be used to find whether the user has specific or not. "Edit Address Info" is the role name that we are checking.

function checkRole()
{
   IsUserHaveRequiredRole("Edit Address Info")
}
function IsUserHaveRequiredRole(rolename) {
    var currentUserRoles = Xrm.Page.context.getUserRoles();
    var Query = "/RoleSet?$filter=Name eq '" + rolename + "'";
    var Result = getRESTQueryResult(Query);

    var currentUserRoles = Xrm.Page.context.getUserRoles();
    var HasRole = false;

    for (role in currentUserRoles) {
        for (allowedrole in Result.results) {
            if (currentUserRoles[role] == Result.results[allowedrole].RoleId) {
                HasRole = true;
            }
        }
    }
    return HasRole;
}
function getRESTQueryResult(RESTQuery) {
    var oDataEndPointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
    oDataEndPointUrl += RESTQuery;
    var service = GetRequestObject();
    if (service != null) {
        service.open("GET", oDataEndPointUrl, false);
        service.setRequestHeader("X-Requested-Width", "XMLHttpRequest");
        service.setRequestHeader("Accept", "application/json, text/javascript, */*");
        service.send(null);
        var requestResults = eval('(' + service.responseText + ')').d;
        return requestResults;
    }
    return '';
}

function GetRequestObject() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
    else {
        try {
            return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch (ex) {
            return null;
        }
    }
}

New features introduced in CRM 2013

1.    New Parameters introduced in Query String parameters:

When you open CRM 2013 form or view in the application by setting in a URL, there are new query string parameter has been introduced that controls how the navigation pane or command bar are displayed. Below two new parameter introduced in CRM 2013 SP1 Release.

1.       Navbar: This parameter controls whether the navigation bar is displayed and whether the application navigation is available via sitemap.
This parameter have three value.
1.       On: The navigation bar is displayed and this is the default behavior when the parameter is not used.

                                                             Fig. 1




2.       Off: The navigation bar will not displayed as you can see the screenshot below.



                                                             Fig. 2


3.       Entity: Only the navigation items of related entity will be visible (as you can see in screenshot) whereas you cannot see the option to navigate the main Tiles.



                                                              Fig. 3
2.       cmdbar: Controls whether the command bar is displayed.

True: The command bar will be displayed. This is default.
False: The command bar will be hidden as you can see in screenshot.




                                                                     Fig. 4

If both command bar and navigation bar is set to false then the page will look like this.




                                                                    Fig. 5

2.       Processes with And/or Group in condition

Earlier the workflow were not flexible to add the grouping condition like OR. We often struggling to put such OR grouping condition in processes. This is much needed feature as we are already using this in Advance Find. But now grouping condition like AND/OR is possible in workflows. This changes is applied in workflows, dialog and SLA Items.
In Previous version we were using multiple condition branches as a work around.
Now with this you can simply add multiple conditions, select the row and group them in OR/AND condition as per the requirements (same as we are using in Advance Find Queries.).

                                                                           Fig. 6

Once you are done with your condition you can hit save and close and your condition will look like this.
         
                                                                               Fig. 7