Wednesday, July 27, 2011

CRM 2011: Canceling the Save operation java script

function Form_onsave(executionObj)
{

//ADD This to avoid save ............
executionObj.getEventArgs().preventDefault();

}

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

CRM 2011 - Filter Views Using Java Script

Call the function Form Load....

function LoadParentMemberAsFullMemberType() {

var viewId = "{65EC9B45-EE81-4F89-BAF6-E8603FF8E1E4}";
var entityName = "account";
var viewDisplayName = "Membership Types";
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='account'>" +
"<all-attributes/>" +
" <link-entity name='mship_membershiptype' from='mship_membershiptypeid' to='mship_membershiptypeid' > " +
" <filter type='and'>" +
"<condition attribute='mship_type' operator='eq' value='Full Member' />" +
" </filter> " +
" </link-entity>" +

"</entity>" +

"</fetch>";



//build grid layout
var layoutXml = "<grid name='resultset' " +
"object='1' " +
"jump='account' " +
"select='1' " +
"icon='1' " +

"preview='1'>" +

"<row name='result' " +

"id='accountid'>" +


"<cell name='mship_companyname' " +
"width='300' />" +
"<cell name='accountnumber' " +

"width='300' />" +
"<cell name='mship_membershiptypeid' " +

"width='300' />" +


"</row>" +

"</grid>";




//add new view view
Xrm.Page.getControl("parentaccountid").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);//Attach to the feild
// Chech The Chenged Field
var membershiptype = crmForm.all["parentaccountid"];
membershiptype.setAttribute("disableViewPicker", "1")


}

Tuesday, July 26, 2011

how to get number of days in a month in c# asp.net?

System.DateTime.DaysInMonth(int year, int month);

Monday, July 25, 2011

Add 1 month to the date time - C#

DateTime nextmonth =DateTime.Today()+ new System.TimeSpan (30, 0, 0, 0 );

Today is  2011/04/01
It Return  2011/05/01

Create Bat File To Start Windows Service in Windows 7

  • Open notepad
  • Write  
        net stop <Service Name>
        net start
<Service Name>
  • Save as filename.bat
  • Run as Administrator

Wednesday, July 20, 2011

CRM 2011 -Adding new activity types

How to create a new activity type

  1. Create a new entity and give it a name 
  2. Check the ‘Define as an activity entity’ check box and keep the ‘Display in Activity Menus’ check box checked
  3. Change the primary field name to reflect your needs
  4. Save your new entity! Publish
  5. It will show in Create new activity >>> Drill Other Activity
 

 

Tuesday, July 19, 2011

Server Error in '/WCFApplication' Application (Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken)


To Resolve this type of Error >>>>

Description: An unhandled exception occurred during the execution of the current Web request. Review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.TypeLoadException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

This error can occur when IIS is installed after installing .NET Framework 4, or if the 3.0 version of the WCF Http Activation module is installed after installing IIS and .NET Framework 4.

To resolve this problem, you must use the ASP.NET IIS Registration Tool (Aspnet_regiis.exe,) to register the correct version of ASP.NET. This can be accomplished by using the –iru parameters when running aspnet_regiis.exe as follows:

aspnet_regiis.exe -iru 

Before Set the Path in command prompt as C:\Windows\Microsoft.NET\Framework64\v4.0.30319

 

Monday, July 18, 2011

CRM 2011 - Add Custom View To SubGrid Using Java Script

Method
function addSubgridCustomView(subgridID, entityTypeCode, displayName, fetchXML, layoutXML, filterType, isDefault) {

    if (IsNull(subgridID)) { throw Error.argument("value", "ID of sub-grid to filter not provided"); return; }
    if (IsNull(entityTypeCode)) { throw Error.argument("value", "Entype code of returned object by fetchXML not provided"); return; }
    if (IsNull(fetchXML)) { throw Error.argument("value", "FetchXml not provide for custom view on sub-grid"); return; }
    if (IsNull(layoutXML)) { throw Error.argument("value", "LayoutXml not provided for custom view on sub-grid"); return; }

    var grd = document.getElementById(subgridID);

    //Check if the sub-grid has any customViews already. 
    var customViews = (IsNull(grd.customViews) ? new Array() : grd.customViews);


    var viewId = "{65EC9B45-EE81-4F89-BAF6-E8603FF8E1E9}";

    //Create an object to hold the customView's information 
    var customView = new Object();
    customView.fetchXml = fetchXML;
    customView.id = viewId;
    customView.layoutXml = layoutXML;
    customView.name = (IsNull(displayName) || displayName == "" ? "Filtered Lookup" : displayName);
    customView.recordType = entityTypeCode;
    customView.Type = (!IsNull(filterType) ? filterType : 0);

    //Add the customView object to the array of customViews 
    customViews.push(customView);

    //Add the array of custom views to the sub-grid 
    grd.customViews = customViews;

    //Set this view as the default if desired 
    if (isDefault) { grd.defaultViewId = viewId; }
Call
function SetProductCategoryView() {
    formType = Xrm.Page.ui.getFormType();
    if (formType == FORM_TYPE_UPDATE) {
        var viewId = "{65EC9B45-EE81-4F89-BAF6-E8603FF8E1E9}";
        var memberID = "";
        var entityName = "fia_memberproductcategory";
        var viewDisplayName = "Product Categories";
        var fetchXml = "<fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">" +

                   "<entity name="fia_memberproductcategory">" +

                   "<attribute name="fia_memberproductcategoryid">" +

                   "<attribute name="fia_name">" +

                   "<order attribute="fia_name" descending="false">" +
                     "<link-entity  ="" from="fia_MemberProductCategoryId" link-type="inner" name="fia_memberproductcategory" to="fia_memberproductcategoryId"> " +

                  "<link-entity  ="" from="fia_memberproductid" link-type="inner" name="fia_fia_memberproduct_account" to="fia_memberproductid"> " +
                               "           <filter type="and">" +
                       "         <condition attribute="accountid" operator="eq" value="E03E2524-CDA6-E011-9F05-BC50FDF3E385">" +
                       "      </condition></filter>   " +
                        "     </link-entity>" +

                        "     </link-entity>" +
                   "</order></attribute></attribute></entity>" +
                   "</fetch>";



        //build grid layout
        var layoutXml = "<grid "="" +<br="" name="resultset">                             "object='1' " +
                             "jump='fia_memberproductcategory' " +
                             "select='1' " +
                             "icon='1' " +

                             "preview='1'&>" +

                         "<row "="" +<br="" name="result">
                              "id='fia_name'&>" +

                           "<cell "="" +<br="" name="fia_name">
                                 "width='300' /&>" +



                         "</cell></row>" +

                       "</grid>";

     

        //add new view view
        addSubgridCustomView("ProductCategory", getObjectTypeCode(entityName), viewDisplayName, fetchXml, layoutXml,0, true);
    }
}

function getObjectTypeCode(entityName) {

    try {

        var lookupService = new RemoteCommand("LookupService", "RetrieveTypeCode");
        lookupService.SetParameter("entityName", entityName);
        var result = lookupService.Execute();

        if (result.Success && typeof result.ReturnValue == "number") {
            alert(result.ReturnValue);
            return result.ReturnValue;
        } else {
            return null;
        }
    }
    catch (ex) {
        throw ex;
    }
}

Tuesday, July 12, 2011

CRM 2011 - Create and Delete Many To Many Relationship Records Using C#

Create >>>>>
            // Code Create Moniker for first Entity: Contact
                    Moniker Moniker1 = new Moniker ( );
                    Moniker1.Id = contactId;
                    Moniker1.Name = "contact";//Entity Name



                    // Code Create Moniker for second Entity: New_CustomEntity
                    Moniker Moniker2 = new Moniker ( );
                    Moniker2.Id = contactTypeId;
                    Moniker2.Name = "mship_contacttype";//Entity Name


         //Many to MAny Relationship Entity Name
                    string strManyToManyRelationshipName = "fia_mship_contacttype_contact";
//Call
AssociateManyToManyEntityRecords ( Moniker1, Moniker2, strManyToManyRelationshipName );

//Method which will associate the records.
        public bool AssociateManyToManyEntityRecords ( Moniker moniker1, Moniker moniker2, string strEntityRelationshipName )
        {
            try
            {
                // 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;
            }

        }


Delete >>>>>

//Method which will associate the records.
        public bool DeAssociateManyToManyEntityRecords ( Moniker moniker1, Moniker moniker2, string strEntityRelationshipName )
        {
            try
            {
                // Create an AssociateEntities request.
                DisassociateEntitiesRequest  request = new DisassociateEntitiesRequest ( );


                // 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;
            }

        }