Friday, 17 August 2012

DebugView

Use Debug.Writeline("...") or Trace.WriteLine("...") and then use debugview to see the trace of execution flow.

Trace.WriteLine("..") goes into release built only

Download it from http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx

Wednesday, 8 August 2012

working with excel in .net


string[] entities = new string[]{"new_custom1","new_custom3","new_custom4"};


 Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

            if (xlApp == null)
            {
                Console.WriteLine("EXCEL could not be started. Check that your office installation and project references are correct.");
                return;
            }
            xlApp.Visible = true;

            Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
            //Worksheet ws = (Worksheet)wb.Worksheets[1];          

            RetrieveAllEntitiesResponse retrieveallEntitiesResponse = (RetrieveAllEntitiesResponse)service.Execute(retrieveEntityRequest);

            foreach (var entityMetadata in retrieveallEntitiesResponse.EntityMetadata)
            {
                if (entityMetadata.LogicalName.Contains("new") && entityMetadata.DisplayName.LocalizedLabels.Count > 0 && entities.Contains(entityMetadata.LogicalName))
                {

                    Microsoft.Office.Interop.Excel.Worksheet newWorksheet;
                    newWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                    newWorksheet.Name = entityMetadata.DisplayName.LocalizedLabels[0].Label;
                    int columnIndex = 1;
                    foreach (var attribute in entityMetadata.Attributes)
                    {
                        if (attribute.LogicalName.Contains("new") && attribute.Description.LocalizedLabels.Count > 0 && !attribute.Description.LocalizedLabels[0].Label.ToLower().Contains("internal"))
                        {
                            newWorksheet.Cells[1, columnIndex].Value2 = attribute.DisplayName.LocalizedLabels[0].Label;
                            newWorksheet.Cells[1, columnIndex].AddComment(attribute.Description.LocalizedLabels[0].Label);

                            columnIndex++;
                        }
                    }
                }
            }

http://csharp.net-informations.com/excel/csharp-format-excel.htm

On or before x number of days


Currently in CRM filter criteria doesn't provide the facility to view records which are are valid on or before 3 days.

IOrganizationService crmService = localContext.OrganizationService;

            object query = localContext.PluginExecutionContext.InputParameters["Query"];
            if (query.GetType() == typeof(QueryExpression))
            {
                QueryExpression qe = (QueryExpression)localContext.PluginExecutionContext.InputParameters["Query"];

                FilterExpression fe = qe.Criteria;

                var filterAttributeCondition = (from c in fe.Conditions
                                                where c.AttributeName == "new_retrievemultiplefilter"
                                                select c).FirstOrDefault();

                if (filterAttributeCondition != null && (string)filterAttributeCondition.Values[0] == "records on or before x number of days")
                {

                    fe.Conditions.Remove(filterAttributeCondition);

                    var xNumberOfDaysCondition = (from c in fe.Conditions
                                                  where c.AttributeName == "new_xnumberofdays"
                                                  select c).FirstOrDefault();

                    if (xNumberOfDaysCondition != null)
                    {
                        int xNumberOfDays = xNumberOfDaysCondition.Values.Count > 0 ? (int)xNumberOfDaysCondition.Values[0] : 0;

                        fe.Conditions.Remove(xNumberOfDaysCondition);

                        DateTime dateOnXnumberDaysBefore = DateTime.Now.AddDays(-xNumberOfDays) ;


                        fe.Conditions.Add(
                            new ConditionExpression(
                                "attributename",
                                ConditionOperator.OnOrBefore,
                                new object[]{dateOnXnumberDaysBefore})
                                );
                    }
                }
            }

Dialog is not showing the many to many entity in the list to create query

When creating the Dialog, and defining the the CRM Query I was not able to see the entity which has a implicit many to many relationship.

Reason: seems to be a bug in crm 2011 product

Resolution: open the many to many relation and change the display option of "Current Entity"and "Other Entity" to "Use Plural Name"

HTML5 - CSS3