Friday, 26 October 2012

Code for creation of new view:

System.String layoutXml =
@"<grid name='resultset' object='3' jump='name' select='1' 
    preview='1' icon='1'>
    <row name='result' id='opportunityid'>
    <cell name='name' width='150' /> 
    <cell name='customerid' width='150' /> 
    <cell name='estimatedclosedate' width='150' /> 
    <cell name='estimatedvalue' width='150' /> 
    <cell name='closeprobability' width='150' /> 
    <cell name='opportunityratingcode' width='150' /> 
    <cell name='opportunitycustomeridcontactcontactid.emailaddress1' 
        width='150' disableSorting='1' /> 

                    System.String fetchXml =
                    @"<fetch version='1.0' output-format='xml-platform' 
    mapping='logical' distinct='false'>
    <entity name='opportunity'>
    <order attribute='estimatedvalue' descending='false' /> 
    <filter type='and'>
        <condition attribute='statecode' operator='eq' 
        value='0' /> 
    <attribute name='name' /> 
    <attribute name='estimatedvalue' /> 
    <attribute name='estimatedclosedate' /> 
    <attribute name='customerid' /> 
    <attribute name='opportunityratingcode' /> 
    <attribute name='closeprobability' /> 
    <link-entity alias='opportunitycustomeridcontactcontactid' 
        name='contact' from='contactid' to='customerid' 
        link-type='outer' visible='false'>
        <attribute name='emailaddress1' /> 
    <attribute name='opportunityid' /> 

                    SavedQuery sq = new SavedQuery
                        Name = "A New Custom Public View",
                        Description = "A Saved Query created in code",
                        ReturnedTypeCode = "opportunity",
                        FetchXml = fetchXml,
                        LayoutXml = layoutXml,
                        QueryType = 0
                    _customViewId = _serviceProxy.Create(sq);
                    Console.WriteLine("A new view with the name {0} was created.", sq.Name);

Friday, 12 October 2012

Hiding navigation pane in mscrm2011:

Javascript approach:

//Ensure navitem is "quoted" to represent string
// bool: true = Visible, false = removed
var objNavItem = Xrm.Page.ui.navigation.items.get(navitem);

C# code approach:

/// Retrieve the sitemap

QueryExpression query = new QueryExpression();
query.EntityName = "sitemap";
query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(true);

EntityCollection col = _service.RetrieveMultiple(query);

Entity sitemap = null;
if (col != null && col.Entities.Count > 0)
   sitemap  = col.Entities[0];
 ///Parse the sitemap entity to an XDocument object
 string sitemapcontent = sitemap["sitemapxml"].ToString();
XDocument sitemapxml = XDocument.Parse(sitemapcontent);

You can now change the sitemap by modifying the sitemapxml object. After you made your changes, it's time to save these changes.

//// Update the sitemap
sitemap["sitemapxml"] = sitemapxml.ToString();

//// Publish the sitemap

PublishXmlRequest request = new PublishXmlRequest();
request.ParameterXml = "<importexportxml><sitemaps><sitemap></sitemap></sitemaps></importexportxml>";

Tuesday, 9 October 2012

converting Managed solution to Unmanaged solution Work around:

This is useful when we have only Managed solution to work with but needs some more customization. Extract the Solution Zip file, Open solution.xml file in notepad application. Search for Managed Tag (E.g.: <Managed>1</Managed>), Now change the value from 1 to 0 and zip the files again and import it. That’s it The Solution is changed to Unmanaged. This can be imported and customized as per the need.

Monday, 1 October 2012


CRM 2011 LINQ Operator Limitations:

.       from

       Supports one from clause per query.


       Represents an inner join. You cannot perform outer joins.


      The left side of the clause must be an attribute name and the right side of the clause must be a value.

      Supported String functions: Contains, StartsWith, EndsWith, and Equals.


      Not supported. FetchXML supports grouping options that are not available with the LINQ query provider.

      For more information, see Use FetchXML Aggregation.


       Supports ordering by entity attributes, such as Contact.FullName.


       Supports anonymous types, constructors, and initializers.


       The last operator is not supported.

          skip and take

       Supports skip and take using server-side paging. The skip value must be greater than or equal to the take value.


       Not supported. FetchXML supports aggregation options that are not available with the LINQ query provider. For more information, see Use FetchXML Aggregation.