Wednesday, November 9, 2011

CRM 2011 - how to set 'Filter On' filter to value 'All' for Activities

Add this Script Library and  add ChangeFilterLoad to Form Load

function ChangeFilterLoad() {
    if (document.getElementById('navActivities') != null) {
        document.getElementById('navActivities').onclick = function () {



function ChangeFilter() {
    //Activity scheduledend options
    var ActivityOptions =
    All: "All",
    Overdue: "Overdue",
    Today: "Today",
    Tomorrow: "Tomorrow",
    Next7Days: "NextXDays;7",
    Next30Days: "NextXDays;30",
    Next90Days: "NextXDays;90",
    Next6Months: "NextXMonths;6"

    //Activity History actualend options
    var HistoryOptions =
    All: "All",
    Today: "Today",
    Yesterday: "Yesterday",
    Last7Days: "LastXDays;7",
    Last30Days: "LastXDays;30",
    Last90Days: "LastXDays;90",
    Last6Months: "LastXMonths;6",
    Last12Months: "LastXMonths;12"

    sArea = "areaActivities";
    //create the iframe object
    var iframe = document.getElementById(sArea + "Frame");
iframe.onreadystatechange = function()
if( iframe.readyState == "complete")
    var picklist, option;
    //reference to the iframe document
    var iframeDoc = iframe.contentWindow.document;
    switch (sArea) {
        case "areaActivities":
            picklist = (iframeDoc.getElementById('crmGrid_Contact_ActivityPointers_scheduledend'));//This is the drop daown id attact to contact form
            /* change to suit your needs */
            option = ActivityOptions.All;
        default: return;
    picklist.value = option;

Monday, November 7, 2011

Backup SQL Server 2008 R2 Restore on SQL 2008

  1. Install an instance of SQL 2008 R2 on one machine and SQL 2008 on another
  2. Open SQL Server Management Studio R2
  3. Select your source Database
  4. Select Tasks>Generate Scripts.
  5. Select 'Script entire database and all database objects', press 'Next'
  6. Select 'Save to File' and click on the 'Advanced' button
  7. Select 'Script for Server Version' and select the version you want: 200/2005/2008
  8. Select 'Type of data to Script' and select Schema/Data/both 
  9. Click 'OK',Next and do it!
  10. Copy the resulting file to the target machine with SQL 2008 [or whatever]
  11. Log onto your SQL Management Studio and open the copied .sql file... be aware that there may be limitations on the file size.

    There may also be issues with the order that the .SQL file inserts the data into the target database and if there are FK constraints in place, this could be an issue.... simply re-order the insert lists.

  12. Once the .sql file is organised, parse it [just to sure], and then execute. 
Refer :

Thursday, October 27, 2011

CRM 2011 - Form Loading Error

Error Message: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Error Details: Exception of type 'System.Web.HttpUnhandledException' was thrown. Source File: Not available Line Number: Not available Request URL: Stack Trace Info: [NullReferenceException: Object reference not set to an instance of an object.] at Microsoft.Crm.Application.Controls.AppNavigationBar.CreateOrderedAreas(NavPaneItems navPaneItems)

To Resolve This Import Customization Again as Manage Solution.

Tuesday, October 18, 2011

Run 32 bit .NET applications on 64 bit machines

Open up command prompt and type this command

C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe SetWow

Now you should be able to run apps that use only the .NET 32 bit CLR.

To revert back to the default 64 bit framework run

C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe Set64

Wednesday, October 12, 2011

Java Script Error - INVALID_CHARACTER_ERR (5) -.createElement

Error In,
document.createElement(<div id="div1">)

To Resolve This,
Create div tag separately and add attribute after created element.
var divEle=document.createElement('div');
divEle.setAttribute("id", "div1");

Monday, October 3, 2011

CRM 2011 - Day Light Issue-Convert Date Time C# Code

Get DaylightChanges hours in CurrentTimeZone and add it to the Date.
//CurentDate Date Time Save in the CRM
TimeZone localZone = TimeZone.CurrentTimeZone;
DaylightTime hours= localZone.GetDaylightChanges ( CurentDate.Year );
CurentDate = CurentDate.AddHours ( hours.Delta.Hours );

Wednesday, September 28, 2011

How to retrieve the optionset text and value in CRM 2011

var selectedOptionSet = Xrm.Page.getAttribute("fieldname");

var textVal= (selectedOptionSet.getSelectedOption().text);
var val=(selectedOptionSet.getSelectedOption().value);

Tuesday, September 20, 2011

CRM 2011 - Moniker

To Map Many To Many Relation Ship Use Moniker Like This in Crm 2011
User EntityReference instead of Moniker

Microsoft.Xrm.Sdk.EntityReference Moniker1 = new Microsoft.Xrm.Sdk.EntityReference { Id = new Guid ( contactID ), Name = "contact" };
Microsoft.Xrm.Sdk.EntityReference Moniker2 = new Microsoft.Xrm.Sdk.EntityReference { Id = new Guid ( id ), Name = "fia_newsletter" };

string strManyToManyRelationshipName = "fia_contact_fia_newsletter";

isSuccess = newsLetterBO.AssociateManyToManyEntityRecords ( Moniker1, Moniker2, strManyToManyRelationshipName );


public bool AssociateManyToManyEntityRecords ( EntityReference moniker1, EntityReference moniker2, string strEntityRelationshipName )
// Create an AssociateEntities request.
AssociateEntitiesRequest request = new AssociateEntitiesRequest ( );

// Set the ID of Moniker1 to the ID of the lead.
request.Moniker1 = new EntityReference { Id = moniker1.Id, LogicalName = moniker1.Name };

// Set the ID of Moniker2 to the ID of the contact.
request.Moniker2 = new EntityReference { Id = moniker2.Id, LogicalName = moniker2.Name };

// Set the relationship name to associate on.
request.RelationshipName = strEntityRelationshipName;

// Execute the request.
this.Service.Execute ( request );

return true;

catch ( SoapException ex )
return false;


This is solution for the error
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Crm.Sdk, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Thursday, September 15, 2011

CRM 2011 - Retrieve Entity Metadata C#

// Get the name of the entity
// Note: We have to convert this to lower because RetrieveEntityMetadata expects the schema name
string entityName ="contact";

// Get the metadata for the currently list's entity
// This metadata is used to create a "Property Descriptor Collection"
RetrieveEntityRequest mdRequest = new RetrieveEntityRequest ( )
{ EntityFilters = EntityFilters.All,
LogicalName = entityName,
RetrieveAsIfPublished = false

// Execute the request
RetrieveEntityResponse entityResponse = ( RetrieveEntityResponse ) this.ServiceProxy.Execute ( mdRequest );

EntityMetadata entityData = entityResponse.EntityMetadata;

//To Get Option Set Data
var preferdList= ( entityData.Attributes.Where ( p => p.LogicalName == "preferredcontactmethodcode" ) ).ToList ( ).FirstOrDefault ( ); ;

if ( preferdList != null ) {

PicklistAttributeMetadata optionList= preferdList as PicklistAttributeMetadata;
OptionSetMetadata opValues= optionList.OptionSet;
foreach ( var op in opValues.Options ) {

preferedMethod.Add ( new OptionSet { Value = op.Value.Value, Text = op.Label.LocalizedLabels[0].Label.ToString() } );


Monday, September 12, 2011

ssrs 2005 multi value parameters allow null values

Create dataset and map with parameter and set multi value.
Select UserId, UserName from user

Then create other data set same feild names and Set as a Default data set
like -------------
Select '11111111-1111-1111-1111-111111111111' as UserId, '' as UserName

Validate your sql.....

IF (@User ='11111111-1111-1111-1111-111111111111' )

Now it works fine :)

Thursday, September 8, 2011

Blank page at end in PDF -SQL 2005 Reporting Services

To Resolve This
Add page margins to zero:
topmargin = 0, rightmargin = 0, leftmargin = 0 and bottommargin = 0
In the Report

Monday, August 29, 2011

CRM 2011-Inactive Recordes C#

public bool InactiveRecord ( string entity, Guid id )
SetStateRequest req = new SetStateRequest ( );

//the entity you want to change the state of
req.EntityMoniker = new EntityReference ( entity, id );

//what should the new state be
req.State = new OptionSetValue ( ( int ) AccountState.Inactive );

//Pick an option from the status reason picklist to specify reason for state change
req.Status = new OptionSetValue ( 2 );

this.Service.Execute ( req );

return true;

catch ( SoapException ex )
return false;

InactiveRecord ( "account",new Guid( "894CC46A-B0CB-4AB0-8BF6-200544E46A2D") ) ;

Wednesday, August 24, 2011

CRM 2011-Fetch XML To Map Many to Many Relationships

After Create Many to many relationship in crm 2011 it created join entity(Relationship name) in crm data base.

Eg - Account Entity Map With Product Entity using Many to many relationship,then sql create center entity called relationship name(account_product)

When you write the fetch xml to get Account related products the you can use account_product as linked entity.

<fetch version='1.0' mapping='logical' output-format='xml-platform' >
<entity name='account'>
<link-entity name='account_product' from='accountid' to='accountid' >

Wednesday, August 10, 2011

Scheduling automated backup using SQL server 2008

It is very important to take backups for the database files on regular basis. Microsoft SQL server 2008 made this task very easy. In this blog, I am going through step by step that will allow
  • Users to schedule the backup to be taken on a particular interval
  • Delete the backup copies after a certain period of time

Schedule the database backup

First I am going to tell you the steps required to schedule the backup. Login to Sql Management studio and connect to the required database. Now from the object explorer, make sure SQL server agent is running, if not start SQL server agent(Right click and press start).
Expand the Management Node from the object explorer, and then select the maintenance plan node. To schedule maintenance plan, you need to have “SYSADMIN” database role. If you dont see the maintenance node, make sure you have the necessary permission. 

Right click the maintenance plan and then select “new maintenance plan”.
Enter the maintenance plan name in the popup box (This can be any name that identifies your task for ). This will identify your backup plan and you should choose a relevant name that suits your plan.


Now you will be in the configuration page for the maintenance plan. . Note the marked area, these are the two areas you need to use for setting up the maintenance plan. The marked area in the right top will be used to configure the time that the plan executes. Choose a time so that the database is least used. The bottom left pane shows the tasks that can be utilized to create an sql maintenance plan. since explaining all of them is not in the scope of this document, I am going to explore only two of them.

Click on the calendar item shown in the right side top. This will bring the job schedule properties popup window that configure the execution time/frequency of the tasks. Configure the data carefully so that it suits your requirement. Usually database backups are taken daily basis. Make sure you are selecting proper time so that your database is least used. Click ok once you finish.

From the maintenance plan tasks pane in the left side, select the backup database plan, this will be used to take backups for the databases. Drag and drop backup database task to the right side(as shown in the diagram).


Double click on the backup database task, it will open up a new window that allows you to configure the database configuration for the backup. Here you configure the databases that you need to backup, then specify a location for the backup, specify the extension for the backup files etc.
From the pop up modal window, by clicking on “Databases” dropdown, you will be able to select the required databases. Also configure the file location, extension for the backup file etc.


Click ok once finished. Now backup plan configuration is over. The backup files will be created on the scheduled time to the mentioned folder. The name of the file will be created by appending the date so that you can identify the back up for a particular date.
Since the backup files are created frequently,… it is a good practice that you delete backup files after a certain period of time. For this you need to execute clean up task  along with the maintenance plan. You can configure the clean up task as follows.
From the left side pane, drag and drop maintenance cleanup task.

Double click on the dropped item inorder to edit the clean up properties. Here you need to specify the backup location, and file extension for the back up files and specify the age of the file. It is a good practice that you keep one month old data, and delete anything prior to one month. 

Once you click ok, then save the maintenance plan. You can either wait till the next execution time or execute it manually inorder to check whether everything is working fine.

This Content Refer From

Sunday, August 7, 2011

How to Apply ampersand (&) in XML

User This Text
&, ", <, >

&amp;, &quot;, &lt;, &gt;

Refer >>>

CRM 2011 - Change Subgrid View Java Script

Use This java script On Form Load...

Change the Fetch XML and set the subgrid ID
function UpdateSubGrid()
    var leadGrid = document.getElementById("Contact");//Set Subgrid ID  
  //If this method is called from the form OnLoad, make sure that the grid is loaded before proceeding
  if (leadGrid.readyState != "complete")
      //The subgrid hasn't loaded, wait 1 second and then try again
      setTimeout('UpdateLeadSubGrid()', 1000);

 var fetchXml = "              ";//Set Fetch XML
  //Inject the new fetchXml
  leadGrid.control.setParameter("fetchXml", fetchXml);
  //Force the subgrid to refresh


Tuesday, August 2, 2011

Pass xml to WCF Rest Service

In Data Contract >>Activity is Custom Object Format

  [OperationContract ( Action = "ReadyMembershipAPI/CreateActivity" )]
        [FaultContract ( typeof ( ApplicationException ) )]
        [WebInvoke ( Method = "POST",
            ResponseFormat = WebMessageFormat.Xml,
            RequestFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "CreateActivity?requestToken={requestToken}" )]
        Guid CreateActivity ( string requestToken, Activity activity );

In Service.svc

public Guid CreateActivity ( string requestToken, FIAActivity activity )
            Guid activityID=Guid.Empty;
                  //Implement Your Code ;
                    return contactHandler.CreateActivity ( organisationName, activity.ContactID, activity.ActivityType,( activity.ActivityDate), activity.Label, activity.Description );


In Activity Object

    [DataContract ( Namespace = "" )]
    public class Activity

        [DataMember ( Order = 1 )]
        public string ContactID { get; set; }

        [DataMember ( Order = 2 )]
        public string ActivityId { get; set; }

        [DataMember ( Order = 3 )]
        public string ActivityType { get; set; }

        [DataMember ( Order = 4 )]
        public DateTime ActivityDate { get; set; }

        [DataMember ( Order = 5 )]
        public string Label { get; set; }

        [DataMember ( Order = 6 )]
        public string Description { get; set; }


Access The Service>>>>

Host Service As


Then Access 

             HttpWebRequest req = null;
             HttpWebResponse res = null;
              const string url = "http://localhost:35798/RestServiceImpl.svc       /CreateActivity?requestToken=tokenabc";

                req = ( HttpWebRequest ) WebRequest.Create ( url );
                req.Method = "POST";
                req.ContentType = "application/xml; charset=utf-8";
                req.Timeout = 30000;
                req.Headers.Add ( "SOAPAction", url );

                var xmlDoc = new XmlDocument { XmlResolver = null };
                xmlDoc.Load ( Server.MapPath ( "PostData.xml" ) );
                string sXml = xmlDoc.InnerXml;
                req.ContentLength = sXml.Length;
                var sw = new StreamWriter ( req.GetRequestStream ( ) );
                sw.Write ( sXml );
                sw.Close ( );

                res = ( HttpWebResponse ) req.GetResponse ( );
                Stream responseStream = res.GetResponseStream ( );
                var streamReader = new StreamReader ( responseStream );

                //Read the response into an xml document
                var soapResonseXmlDocument = new XmlDocument ( );
                soapResonseXmlDocument.LoadXml ( streamReader.ReadToEnd ( ) );

                //return only the xml representing the response details (inner request)
                TextBox1.Text = soapResonseXmlDocument.InnerXml;//Here Retun Guid as xml

PostData.xml >>>>
<Activity  xmlns="">


Refer >>

Wednesday, July 27, 2011

CRM 2011: Canceling the Save operation java script

function Form_onsave(executionObj)

//ADD This to avoid save ............


When add this function in Form On save check the pass execution context as first parameter checkbox