Monday, 19 October 2015

23:19 - No comments

Interview Question




  1. What is Final block ?
  2. What is CLR ?
  3. Validation in ASP.Net
  4. How to install Database in CRM or How to map database to CRM ?
  5. What is Fetch XML ?
  6. What is foreachloop?
  7. What is Ribbon ? How to add the Ribbon.?
  8. What is Isolation Mode?
  9. What is Web resource
  10. What the messages in there in Plugin ?
  11. What is Exception Handling ?
  12. If you export the solution what are there inside the solution ? 
  13. What is Matadata in Dynamic CRM ?
  14.  I have a Entity, I didnot add any JavaScript function for that Entity. If i open the Entity i am getting JavaScript runtime error. So Where i need to check for this error ?
  15. What is Retrieve Multiple ? How Many records can we retrieve using Retrieve Multiple ?
  16. what is Custom Workflow?
  17. How to create Entity,Fields,Values in CRM Database ?
  18. What is SQL  Architecture,Table ?
  19. Custom Application ?
  20. What is XML File ?

Wednesday, 14 October 2015

03:47 - No comments

CRM 2011 Usefull JavaScripts | MS CRM



Get the value from a CRM field
var value = Xrm.Page.getAttribute(“CRMFieldSchemaName”).getValue();
Set the value of a CRM field
Xrm.Page.getAttribute(“CRMFieldSchemaName “).setValue(“New Value”);
Get the value from a CRM OptionSet field
var value = Xrm.Page.getAttribute(“CRMOptionSetSchemaName”).getValue();
Get the text from a CRM OptionSet field
var text = Xrm.Page.getAttribute(“CRMOptionSetSchemaName”).getText();
Set the value of a CRM OptionSet field
Xrm.Page.getAttribute(“CRMOptionSetSchemaName”).setValue(“1”); // OptionSet Value
Get the selected text of a CRM OptionSet field
Xrm.Page.getAttribute(“CRMOptionSetSchemaName”).getSelectedOption().text;
Get the selected value of a CRM OptionSet field
Xrm.Page.getAttribute(“CRMOptionSetSchemaName”).getSelectedOption().value;
Get the text and value of a CRM Lookup field
var lookupObject = Xrm.Page.getAttribute(“CRMLookupSchemaName”).getValue();
lookupObject[0].name; // text of lookup
lookupObject[0].id; // Guid of lookup
Set the value of a CRM Lookup field
var lookupData = new Array();
var lookupItem = new Object();
lookupItem.id = “4A2A54CB-349C-E111-8D26-1CC1DEE8DA78”; // Guid of record
lookupItem.name = “New Contact”; // Entity record name
lookupItem.entityType = “EntitySchemaName”;
lookupData[0] = lookupItem;
Xrm.Page.getAttribute(“CRMLookupSchemaName”).setValue(lookupData);
Disable CRM field
Xrm.Page.ui.controls.get(“CRMFieldSchemaName”).setDisabled(true);
Hide CRM field
Xrm.Page.ui.controls.get(“CRMFieldSchemaName”).setVisible(false);
Hide a Tab in CRM
Xrm.Page.ui.tabs.get(“tabName”).setVisible(false);
Hide a Section in CRM
var tab = Xrm.Page.ui.tabs.get(“tabName”);
tab.sections.get(“sectionName”).setVisible(false);
Set the Requirement level in CRM
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“required”);
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“none”);
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“recommended”);
Set Focus on a field in CRM
Xrm.Page.ui.controls.get(“CRMFieldSchemaName”).setFocus(true);
Cancelling Onsave Event in CRM
event.returnValue = false;
return false;
Check IsDirty in CRM field
var isDirty = Xrm.Page.getAttribute(“CRMFieldSchemaName”).getIsDirty();
alert(isDirty); // returns true if the field is dirty
Check IsDirty for all the fields in CRM
var isDirty = Xrm.Page.data.entity.getIsDirty();
alert(isDirty); // returns true if any of the field is dirty in the entire form.
Force Submit a read only field in CRM
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setSubmitMode(“always”);
Preventing an attribute to be saved in CRM form
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setSubmitMode(“never”);
Get Unique Organization Name in CRM
Xrm.Page.context.getOrgUniqueName();
Get Server url in CRM
Xrm.Page.context.getServerUrl();
Get the record Id in CRM
Xrm.Page.data.entity.getId();
Get the User Id in CRM
Xrm.Page.context.getUserId();
Get the Entity Schema Name in CRM
Xrm.Page.data.entity.getEntityName();
Get the UserRole Id’s in CRM
var userRoles = Xrm.Page.context.getUserRoles();
for (var i = 0; i < userRoles.length; i++)
{
var userRole = userRoles[i]; // returns the Role Id
}
Get the Form Type in CRM
Xrm.Page.ui.getFormType();
Form Types in CRM
Is the user creating a new record?
Xrm.Page.ui.getFormType() == “1”
Is the user updating an existing record?
Xrm.Page.ui.getFormType() == “2”
Is the user unable to update this record?
Xrm.Page.ui.getFormType() == “3”
Is this record deactivated?
Xrm.Page.ui.getFormType() == “4”
Is the user using the Quick Create form?
Xrm.Page.ui.getFormType() == “5”
Is the user using the Bulk Edit form?
Xrm.Page.ui.getFormType() == “6”
Save a record in CRM
Xrm.Page.data.entity.save(); // for saving a record
Xrm.Page.data.entity.save(“saveandclose”); // for save and close
Xrm.Page.data.entity.save(“saveandnew”); // for save and new
Close the form in CRM
Xrm.Page.ui.close();

Tuesday, 10 March 2015

23:38 - 2 comments

JavaScript Code for Age Calculation from Date of Birth | MS CRM


Age Calculation:

Add Java Scripts code as on change of Date Of Birth field value Then you will get age value when ever Date Of Birth value change.


function CalcAge()
{
    var now = new Date(); //Todays Date  
    var birthday = Xrm.Page.getAttribute("new_dob").getValue(); //Get the Date of Birth value 
    
    var diff = now.getMonth() - birthday.getMonth();  //Check to see if Birthday has already passed
if (diff > -1) //If Birthday has already occurred  
    {
        var bd1 = now.getFullYear() - birthday.getFullYear();
        //set the age attribute
        Xrm.Page.getAttribute("new_a").setValue(bd1.toString()); 
    }
    else //If Birthday has not already occurred 
    {
        var bd2 = now.getFullYear() - birthday.getFullYear() - 1;
        Xrm.Page.getAttribute("new_a").setValue(bd2.toString());
    }

}

Monday, 9 March 2015

22:18 - No comments

Filtering the sub grid records in dynamics CRM | MS CRM



Create a sub grid in the required entity.

For example I am adding Account sub grid in Lead entity Form:




Go to Settings Ã  Customizations à Customize the system à Select the entity (Account) à Views



In views open Account Lookup view, Edit Filter criteria in that add condition


Now save and publish, then you will get the particular sub grid filter 

00:42 - No comments

Implementing Auto Numbering function using plugin in CRM: | MS CRM


Here I am going to create auto numbering plugin for lead entity

Step 1:
First create one custom entity for Auto Numbering. Which is used for configuring auto numbering operation.


Step 2:

Create following fields
1.       Entity Name
2.       Prefix or Postfix
3.       Starting Number


Step 3:
Create a field to display auto number in the required entity


Step 4:
Using the code below create a plugin for auto number generation.




Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Crm.Sdk.Messages;
using System.ServiceModel;
using System.Runtime.Serialization;


namespace AutoNumberPlugin
{
    public class Class1:IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
  IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.
GetService(typeof(IPluginExecutionContext));
 IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.
GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                Entity entity = (Entity)context.InputParameters["Target"];

                if (entity.LogicalName == "lead")
                {

                    try
                    {
                        var fetchXml ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
                            fetchXml +="<entity name='new_auto'>";
                            fetchXml +="<attribute name='new_autoid' />";
                            fetchXml +="<attribute name='new_name' />";
                               fetchXml +="<attribute name='new_prefix' />";
                               fetchXml +="<attribute name='new_startingnumber' />";
                            fetchXml +="<attribute name='createdon' />";
                            fetchXml +="<order attribute='new_name' descending='false' />";
                            fetchXml +="<filter type='and'>";
                            fetchXml +="<condition attribute='new_name' operator='eq' value='"+entity.LogicalName+"' />";
                            fetchXml +="</filter>";
                            fetchXml +="</entity>";
                            fetchXml +="</fetch>";
                            var result = service.RetrieveMultiple(new FetchExpression(fetchXml));
                            if (result.Entities.Count > 0)
                            {
                                Guid AutoNumberId = ((Guid)result.Entities[0].Attributes["new_autoid"]);
                                String Prefix = ((String)result.Entities[0].Attributes["new_prefix"]);

                                String Number = ((String)result.Entities[0].Attributes["new_startingnumber"]);

                                Int32 No = Convert.ToInt32(Number);
                                No = No + 1;

                                String ACCcode = Prefix + (Convert.ToString(No)).PadLeft(4, '0');

                                ColumnSet attributes1 = new ColumnSet(new string[] { "leadid", "new_lead_id" });
                                Entity acc = service.Retrieve("lead", entity.Id, attributes1);
                                if (!(acc.Contains("new_lead_id")))   
                                {
                                    acc.Attributes["new_lead_id"] = ACCcode;
                                    service.Update(acc);


                                    ColumnSet attributes2 = new ColumnSet(new string[] { "new_startingnumber" });
                                    Entity ano = service.Retrieve("new_auto", AutoNumberId, attributes2);
                                    ano.Attributes["new_startingnumber"] = Convert.ToString(No);
                                    service.Update(ano);
                                }
                            }


                    }
                    catch (Exception ex)
                    {
                        throw new InvalidPluginExecutionException("An error occured in plugin. " + ex, ex);
                    }
                }
            }
        }


    }



}

Sunday, 8 March 2015

22:12 - 2 comments

Delete a Record in CRM using OData Query | MS CRM



To Delete a record in CRM, we require JQuery min 1.4 &  JSON2 script file which we can get from SDK from this specific path
SampleCode\JS\RESTEndpoint\JavaScriptRESTDataOperations\JavaScriptRESTDataOperations\Scripts

Now add the following code to your web resource,
Also add JSon.js and Jquery1.4min.js to the Library 

---------->


function delete()
{
var lookupObject = Xrm.Page.getAttribute("new_lookup").getValue();   //getting the id through lookup
var id = lookupObject[0].id;
var set="your entity schema nameSet"
deletelog(id,set);
}

function deletelog(id,odata)
{
 var serverUrl = Xrm.Page.context.getServerUrl();
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
    $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'"+id+"')",
    beforeSend: function (XMLHttpRequest) {
    XMLHttpRequest.setRequestHeader("Accept", "application/json");
    XMLHttpRequest.setRequestHeader("X-HTTP-Method", "DELETE");
    },
    success: function (data, textStatus, XmlHttpRequest) {
    alert("Deleted successfully");
    },
    error: function (XmlHttpRequest, textStatus, errorThrown) {
    alert("Error while deletion " + errorThrown);
   
    }
    });
}