Tuesday, 16 July 2013

Retrieving Subgrid Items count using Javascipt in MS CRM 2011/MS CRM 2013

Retrieving Subgrid Items count using Javascipt.

1.Get the subgrid  using "Name" of subgrid as given below.
















2.Write the Javascript function as given below:

function subgridItemCount() {
 
      // Get the Subgrid Control
    var grid = Xrm.Page.ui.controls.get('LineItems')._control;
    if (grid.get_innerControl() == null) {
        setTimeout(subgridItemCount, 1000);
        return false;
    }
    else if (grid.get_innerControl()._element.innerText.search("Loading") != -1) {
        setTimeout(subgridItemCount, 1000);
        return false;
    }
    var countRec = grid.get_innerControl().get_allRecordIds().length;
    if (countRec > 0) {
        alert(countRec);
 
    }
 
}


For MS CRM 2013:

function FindControl() {
    if (document.getElementById('subgridName')!= null) {
        var count=document.getElementById('subgridName').control.get_totalRecordCount();
        alert(count);
        }
        else {
            setTimeout("FindControl()", 1000);
        }
    }


3.Result




























Hope this helps,

Regards,

Yusuf

Tuesday, 2 July 2013

Retrieve N:N records in MS CRM 2011

Retrieving N:N records in MS CRM 2011 using LINQ requires less code and is straightforward.

I am assuming that "Account" is in N:N relationship with "Custom Entity".

Below is the screenshot for relationship





















Here is the Screenshot of account having custom entity records





























Query:

LINQ query to get all the N:N custom entity records for the above Account.

 string accountId = "CC572EC9-01E3-E211-AC62-984BE173A384";
  var customEntities = (from NtoN in makeUseOfContext.new_customentity_accountSet
                        where NtoN.accountid.Value == new Guid(accountId) && 
                        NtoN.new_customentityid != null
                         select new { 
                                    customentityid = NtoN.new_customentityid.Value 
                                   }).ToList();
        
Debug Mode:

















Similarly we can get the Accounts associated to the custom  entity.
Hope it will help someone somewhere :)

Thanks,
Yusuf

Microsoft Dynamics CRM - Orion release

The next major release of Microsoft Dynamics CRM will come in the form of the Orion release in the second half of 2013.

Major Changes:
.
The major themes for the Orion release are as follows:
• User Experience – Continuation of the journey in Polaris
• Ubiquitous – Role-tailored applications for Sales Professionals. (Ubiquitous key word replaces the word Mobile. You will be hearing this a lot more).
• Productivity – Internal Collaboration for the on-premise customers & Server Sync enhancements
• Business Process – Process-centric theme continued to the next level
• Online – Online first focus to continue (this means CRM Online will get all the new features first before OnPremise)

Orion User Interface:

Firstly, you will notice it has no ribbon. Next it has no left navigation bar. The navigation bar is now at the top (as shown in purple colour in the screenshot below).



Here is the full post.Refer this too.



Regards,

Yusuf

Friday, 21 June 2013

CRM 2011 – New SDK version 5.0.16 available

The MS CRM Team have released an updated CRM 2011 SDK version 5.0.16 which can be downloaded here http://www.microsoft.com/en-us/download/details.aspx?id=24004 or viewed on MSDN here http://msdn.microsoft.com/en-us/library/gg309408.aspx Check out the SDK Release History notes herehttp://msdn.microsoft.com/en-us/library/dn198205.aspx

Now the common question here is that what is changing in the new version.There are some changes please go through below post on

MSCRM Bing’d




Regards,
Yusuf

Friday, 24 May 2013

Using Child Workflows in MS CRM 2011.

While working with the Projects we have to implement several logic as per the Client Need.

Here is the requirement.

1)Case Severity can be (1,2,3,4) Where 1 is the highest and 4 is the lowest.
2)Whenever Severity is raised to 1.It should trigger a mail to an user and keep on sending until Status of the Case is Closed.

Solution:

1)"Keep on sending until Status of the Case is Closed" this Can be achieved using child workflow.
2)"Whenever severity is raised to 1" :It means we should compare the previous severity with the new severity.

Note:
So we should Create  a custom field "previous severity".Set this field  with the value of case severity.When the Case is Created.You can achieve this using either workflow or JavaScript.

Creating Workflows:We will create two workflows

1)Main Workflow
2)Child workflow

Main workflow will call the child workflow and child workflow will call itself to achieve this.

Main Workflow Screen shot:



Child Workflow Screen shot:













Note : This workflow is on change of "Severity" of case.

Hope this helps,

Regards,

Yusuf

Clone an Opportunity in MS CRM 2011 by Plugin.

Below is a Plugin to create an Opportunity Clone [Cloning opportunity products as well].It uses early bound approach.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Sdk.Messages;
using Entities = Pes.My.Configurations.Entities;
using System.ServiceModel;
using Pes.My.Configurations.Entities;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Client;
 
namespace My.Crm.Plugins.Opportunity
{
    public class PostUpdate : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            Entities.Opportunity oppRec;
 
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
 
            // This plug-in was fired from the playback queue after the user selected to go online within Microsoft Dynamics CRM for Outlook.
            if (context.IsExecutingOffline || context.Depth > 1)
                return;
 
 
            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"is Entity)
            {
 
                //Verify that the entity represents an Opportunity
                if (((Entity)context.InputParameters["Target"]).LogicalName != Pes.My.Configurations.Entities.Opportunity.EntityLogicalName || context.MessageName != "Update")
                    return;
                else
                    oppRec = ((Entity)context.InputParameters["Target"]).ToEntity<Pes.My.Configurations.Entities.Opportunity>();
            }
            else
            {
                return;
            }
 
            try
            {
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
 
 
                using (var MyContext = new MyContext(service))
                {
 
                    if (oppRec.My_IsCloned == true)
                    {
                        if (context.Depth == 1)
                        {
 
                            Entity opportunity = null;
 
                            opportunity = service.Retrieve(Entities.Opportunity.EntityLogicalName, oppRec.Id, new ColumnSet(true));
 
                            Entity cloneopportunity = new Entity();
 
                            opportunity.Attributes.Remove("opportunityid");
                            opportunity.Id = Guid.NewGuid();
 
                            cloneopportunity = opportunity;
                            Guid ClonedOppId = service.Create(cloneopportunity);
 
 
                            List<Entities.OpportunityProduct> listoppproduct = MyContext.OpportunityProductSet
                                      .Where(acp => acp.OpportunityId.Id == oppRec.Id).ToList<Entities.OpportunityProduct>();
                            foreach (OpportunityProduct objoppproduct in listoppproduct)
                            {
                                cloneOppProduct((Guid)objoppproduct.Id, ClonedOppId, service);
                            }
 
 
                        }
 
                    }
 
                }
 
 
            }
            catch (InvalidPluginExecutionException)
            {
                throw;
            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
            }
 
        }
 
        private void cloneOppProduct(Guid guid, Guid Opp, IOrganizationService service)
        {
 
            Entity opportunityproduct = null;
            opportunityproduct = service.Retrieve(Entities.OpportunityProduct.EntityLogicalName, guid, new ColumnSet(true));
 
            Entity cloneopportunityproduct = new Entity();
 
            opportunityproduct.Attributes.Remove("opportunityproductid");
            opportunityproduct.Attributes.Remove("opportunityid");
            opportunityproduct.Id = Guid.NewGuid();
            opportunityproduct.Attributes["opportunityid"] = new EntityReference(Entities.Opportunity.EntityLogicalName, Opp);
            cloneopportunityproduct = opportunityproduct;
            service.Create(cloneopportunityproduct);
 
        }
    }
}



Note: I run this plugin from ribbon button "Clone Opportunity".Here I am setting Custom field "My_IsCloned " to true and saving the form using javaScript.And On post update it triggers this plugin.


Also you have to create an early bound class using CrmSvcUtil  below is an example

CrmSvcUtil.exe /out:MyEntities.cs /url:https://Mydev1.api.crm.dynamics.com/XRMServices/2011/Organization.svc /username:name@My.com /password:pass123 /namespace:Pes.My.Configurations.Entities /serviceContextName:MyContext 

Use the class generated i.e MyEntities [here] in your project and accomplish the same.

Hope this helps.

Yusuf