Cleared Microsoft Dynamics CRM 2013 Customization and Configuration ( MB2 – 703 ) Exam today


Cleared Microsoft Dynamics CRM 2013 Customization and Configuration ( MB2 – 703 ) Exam today which contains mainly below topics.

  • Business Process Flow
  • Dashboard and Charts
  • Access Teams
  • Quick Create Forms
  • Views
  • CRM for Tablets

Set Custom View as Default View for Lookup Control


Let’s say we have to set Custom View as Default View of a particular Lookup. Below are the steps to set Custom View as default View.

1. Create a Custom View as per your requirement and Save it.(In my case, Created a custom view of Account which will be shown on contact entity for Primary Customer Field)
CustomView

2. Get View Id from Browser. 3. Download Fetch XML for your custom view as shown below. In my case, below is the FetchXML query..

<fetch version=”1.0″ output-format=”xml-platform” mapping=”logical” distinct=”false”>   <entity name=”account”>     <attribute name=”name” />     <attribute name=”primarycontactid” />     <attribute name=”telephone1″ />     <attribute name=”accountid” />     <attribute name=”accountratingcode” />     <order attribute=”name” descending=”false” />     <filter type=”and”>       <condition attribute=”telephone1″ operator=”eq” value=”555-0135″ />     </filter>   </entity> </fetch>

4. Format the FetchXML  as string variable as below.

    var fetchXml = “<fetch version=’1.0′ “ +
 “output-format=’xml-platform’ “ +
 ” mapping=’logical’ “ +
 ” distinct=’false’>” +
  “<entity name=’account’>” +
    “<attribute name=’name’ />” +
    “<attribute name=’primarycontactid’ />” +
    “<attribute name=’telephone1′ />” +
    “<attribute name=’accountid’ />” +
    “<attribute name=’accountratingcode’ />” +
    “<order attribute=’name’ descending=’false’ />” +
    “<filter type=’and’>” +
     ” <condition attribute=’telephone1′ operator=’eq’ value=’555-0135′ />” +
    “</filter>” +
  “</entity>” +
“</fetch>”;
5. Create layoutXml to set Grid properties to display the view as below.
var layoutXml = “<grid name=’resultset’ “ +
“object=’1′ “ +
“jump=’name’ “ +
“select=’1′ “ +
“icon=’1′ “ +
“preview=’1′>” +
“<row name=’result’ “ +
“id=’accountid’>” +
“<cell name=’name’ “ +
“width=’300′ />” +
“<cell name=’primarycontactid’ “ +
“width=’150′ />” +
“<cell name=’telephone1′ “ +
“width=’100′ />” +
“<cell name=’accountratingcode’ “ +
“width=’100′ />” +
“disableSorting=’1′ />” +
“</row>” +
“</grid>”;

6. Call the addCustomView() method of Lookup to set custom view as Default View.

Sets the viewId, viewDisplayName, fetchXml, and layoutXml variables to pass as arguments so that a custom view is added as the default view to the control for the Parent Customer lookup field.

7. Add above steps in a custom function and call it on OnLoad or OnChange as per requirement
function setDefaultCustomView() {
    var viewId = “{00000000-0000-0000-00AA-000010001001}”;
    var viewDisplayName = “Custom Account View”;
    var fetchXml = “<fetch version=’1.0′ ” +
“output-format=’xml-platform’ ” +
” mapping=’logical’ ” +
” distinct=’false’>” +
“<entity name=’account’>” +
“<attribute name=’name’ />” +
“<attribute name=’primarycontactid’ />” +
“<attribute name=’telephone1′ />” +
“<attribute name=’accountid’ />” +
“<attribute name=’accountratingcode’ />” +
“<order attribute=’name’ descending=’false’ />” +
“<filter type=’and’>” +
” <condition attribute=’telephone1′ operator=’eq’ value=’555-0135′ />” +
“</filter>” +
“</entity>” +
“</fetch>”;

    var layoutXml = “<grid name=’resultset’ ” +
“object=’1′ ” +
“jump=’name’ ” +
“select=’1′ ” +
“icon=’1′ ” +
“preview=’1′>” +
“<row name=’result’ ” +
“id=’accountid’>” +
“<cell name=’name’ ” +
“width=’300′ />” +
“<cell name=’primarycontactid’ ” +
“width=’150′ />” +
“<cell name=’telephone1′ ” +
“width=’100′ />” +
“<cell name=’accountratingcode’ ” +
“width=’100′ />” +
“disableSorting=’1′ />” +
“</row>” +
“</grid>”;

Xrm.Page.getControl(“parentcustomerid”).addCustomView(viewId, “account”, viewDisplayName, fetchXml, layoutXml, true); 

}

Note: Pls change the double quote(“) manually before testing the code.

Associate a Security Role on User Creation in CRM 2011 using Async Plugin


Below is the sample code to associate a security role on user creation in CRM 2011. Register the plugin on Post Create of systemuser entity and select execution mode as Asynchronous

 

public void Execute(IServiceProvider serviceProvider)

        {

            // Obtain the execution context from the service provider.

            IPluginExecutionContext context =

                (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

 

            // Get a reference to the organization service.

            IOrganizationServiceFactory factory =

                (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

            IOrganizationService service = factory.CreateOrganizationService(context.UserId);

 

 

// The InputParameters collection contains all the data passed in the message request.

            if (context.InputParameters.Contains(“Target”) &&

                context.InputParameters[“Target”] is Entity)

            {

                // Obtain the target entity from the input parameters.

                Entity entity = (Entity)context.InputParameters[“Target”];

 

                // Verify that the target entity represents a systemuser.

                // If not, this plug-in was not registered correctly.

                if (entity.LogicalName != “systemuser”)

                    return;

 

            try

            {

// get user entity record id

Guid userId=(Guid)context.OutputParameters[“id”];

 

//Get Id of Security Role

Guid securityRoleId=new Guid(“<enter guid here>”)

                // Create the request object

// systemusersroles_association relationship.

AssociateRequest addRolesToUser = new AssociateRequest

{

    Target = new EntityReference(“systemuser”, userId),

    RelatedEntities = new EntityReferenceCollection

    {

        new EntityReference(“role”, securityRoleId)

    },

    Relationship = new Relationship(“systemuserroles_association”)

};

 

// Execute the request.

service.Execute(addRolesToUser);

            }

            catch (FaultException<OrganizationServiceFault> ex)

            {

                // Handle the exception.

            }

        }

}

 hope it will help u !

Revised list of useful Dynamics CRM 2011 tools, utilities, scripts & controls


Very useful information..Thanks for sharing !!

Everything CRM

Sometime ago I wrote a blog post containing over 40 useful tools & utilities for CRM2011. This post was received very well and I decided it’s about time to update the list.

The new list now contains over 70 tools & utilities and includes recent CodePlex projects. Couple of things to note about these utilities:

  • These are freeware or open source utilities, so no commercial tools!
  • I haven’t tested all of the utilities in the list. Some of the projects are still in the early stages of development, but I included them anyway.
  • Not all utilities work for IFD/Online and I haven’t tested if all work with CRM2011. Most of them are designed for 2011, but some are developed for 4.0 but support 2011.

The list is also available in Excel file which you can download here. You can store it future reference and it’s easier to search &…

View original post 1,948 more words

Retrieve Related entity’s field value from client side using oData


Below is the sample of how to retrieve related entity’s field value using oData.

Let’s take a example ..suppose we want to retrieve some field value from SystemUser entity(User Name and EmployeeId) OnLoad of Account where OwnerId of Account is equal to SystemUserId of SystemUser entity.Write below  code on OnLoad of Account entity.

var serverUrl=Xrm.Page.context.getServerUrl();
var ownerId=Xrm.Page.getAttribute(“ownerid”).getValue()[0].id;
var ownerGuid=ownerId.substring(1,ownerId.length-1);

var oDataQuery=serverUrl+”/xrmservices/2011/OrganizationData.svc/SystemUserSet?$select=DomainName,EmployeeId,ParentSystemUserId,AccessMode&$expand=user_accounts&$filter=SystemUserId eq guid'”+ownerGuid+”‘”;

$.ajax(

{
type: “GET”,
contentType: “application/json; charset=utf-8”,
datatype: “json”,
url: oDataQuery,
beforeSend: function(XMLHttpRequest)
{
XMLHttpRequest.setRequestHeader(“Accept”,”application/json”);
},
success: function(data, textStatus, XmlHttpRequest)
{
if(data != null && data.d != null && data.d !=null)
{
var users=data.d.results[0];
var userName=users.DomainName;

//Lookup Manager(ParentSystemUserId)
var managerName=users.ParentSystemUserId.Name;
var managerId= users.ParentSystemUserId.Id;
var managerType=users.ParentSystemUserId.LogicalName;

// OptionSet
var accessMode=users.AccessMode.Value // This will return integer value

var employeeId=users.EmployeeId;
alert(‘User Name : ‘+users.DomainName +’Employee Id :’ +users.EmployeeId);
}
},
error: function(XmlHttpRequest,textStatus,errorThrown)
{
alert(‘oData select failed ‘+ oDataQuery);
}
}
);

Note : don’t forget to load json2.js and jquery1.4.1.min.js  framework on Account Form.

Hope it will help u.