Feedjit

Articles for you

Showing posts with label Crm. Show all posts
Showing posts with label Crm. Show all posts

Sunday, June 15, 2014

Log4net Implementation in CRM 2011, log4net in CRM Plugins, WebServices and Custom aspx Pages.

This post is about log4net logger implementation in CRM 2011. I will provide details about log4net in CRM Plugins. It is as the same with Web-services and Custom aspx Pages.


1. First we will have a Config file for log4net so that, its configuration/settings can be read and applied to logger.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="D:\Logger\Log4net\logs\log.txt" />
      <appendToFile value="false" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="5" />
      <maximumFileSize value="1GB" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
      </layout>
    </appender>
    <appender name="MemoryAppender" type="log4net.Appender.MemoryAppender">
    </appender>
    <root>
      <level value="Info" />
      <appender-ref ref="RollingLogFileAppender" />
      <appender-ref ref="MemoryAppender" />
    </root>
  </log4net>
</configuration
Copy all this into a file named "log4net.config" and place it in D:\Logger\Log4net\Config\

2. Add log4net.dll to your Plugin.

3.
using log4net;
using log4net.Config;
public class MyPlugin: IPlugin
    {
    protected static readonly ILog Logger = LogManager.GetLogger(typeof(PublishToGRID));
    static MyPlugin()
    {
      XmlConfigurator.Configure(new System.IO.FileInfo(@"D:\Logger\Log4net\Config\log4net.config"));
    }
try
{
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
  Logger.Info("Plugin Executed");
}
}
catch (Exception ex)
{
  string ErrorMessage = "Exception Occured in CRM";
  Logger.Error(ErrorMessage,ex);              
}


After your plugin executed: you will se the log file generated in D drive.
containing the following text:

Logger.info: 6/15/2014  7:11 p.m
Plugin Excuted







Thursday, May 29, 2014

CRM 2011 like Subgrid With Sorting in JavaScript, CRM 2011 Display fetchxml in IFrame, Display Custom Advance Find view in Iframe 2014,

Today,
My post is about how to display Related Notes of an Entity in CRM Subgrid with Sorting, Refresh, Delete Multiple and Open Multiple Records:

For Example we want to display all Notes of Account Entity :

  1. First of all Add IFrame to Account Entity with the following Properties:


2. Then Add New JavaScript library to the form Properties and Paste the following code in it.

            function Notes() {
  1.     if (Xrm.Page.ui.getFormType() == 1) {
  2.         return;
  3.     }
  4.     var NotesGrid = document.getElementById("IFRAME_RelatedAttachments");
  5.     if (NotesGrid == null || NotesGrid.readyState != "complete") {

  6.         setTimeout("Notes()", 2000);
  7.         return

  8.     }
  9.     NotesGrid.src = "about:blank";
  10.     var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' count='6'><entity name='annotation'><attribute name='annotationid'/><attribute name='subject'/><attribute name='notetext'/><attribute name='modifiedby'/><attribute name='filename'/><attribute name='isdocument'/><attribute name='filesize'/><attribute name='modifiedon'/><order attribute='modifiedon' descending='false'/><link-entity name='" + Xrm.Page.data.entity.getEntityName() + "' from='" + Xrm.Page.data.entity.getEntityName() + "id" + "' to='objectid' alias='aa'><filter type='and'><condition attribute='" + Xrm.Page.data.entity.getEntityName() + "id" + "' operator='eq'  value='" + Xrm.Page.data.entity.getId() + "'/></filter></link-entity></entity></fetch>";



  11.     var layoutXml = "<grid name='resultset' object='5' jump='subject' select='1' icon='1' preview='1'><row name='result' id='annotationid'><cell name='isdocument' width='40' /><cell name='subject' width='200' /><cell name='filename' width='200' /><cell name='notetext' width='200' /><cell name='filesize' width='100' /><cell name='modifiedby' width='150' /><cell name='modifiedon' width='100' /></row></grid>";


  12.     EmbedAdvancedFindView("IFRAME_RelatedAttachments", "annotation", fetchXml, layoutXml, "name", "false", "{DDDFF6AE-2F52-4640-B2BB-2BA59DA0777C}");

  13.     // to remove the toolbar items from the advance find grid
  14.     var iFrame1 = null;
  15.     iFrame1 = crmForm.all.IFRAME_RelatedAttachments;
  16.     var iDoc1 = iFrame1.contentWindow.document;
  17.     iFrame1.attachEvent("onreadystatechange", Ready1);
  18.     RemoveWhiteSpace();

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function EmbedAdvancedFindView(iFrameId, entityName, fetchXml, layoutXml, sortCol, sortDescend, defaultAdvFindViewId) {
    try {

        var iFrame = document.getElementById(iFrameId);
        var httpObj = new ActiveXObject("Msxml2.XMLHTTP");
        var url = "/" + ORG_UNIQUE_NAME + "/advancedFind/fetchData.aspx";

        var params = "FetchXML=" + fetchXml
        + "&LayoutXML=" + layoutXml
        + "&EntityName=" + entityName
        + "&DefaultAdvFindViewId=" + defaultAdvFindViewId
        + "&ViewType=1039";


        httpObj.Open("POST", url, true);

        httpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        httpObj.setRequestHeader("Content-length", params.length);
        httpObj.onreadystatechange = function () {
            if (httpObj.readyState == 4 && httpObj.status == 200) {
                var doc = iFrame.contentWindow.document;
                iFrame.src = null;
                doc.open();
                doc.write(httpObj.responseText);
                doc.close();
                // doc.body.style.padding = "0px";
                // doc.body.style.backgroundColor = "#eaf3ff";

            }
        }
        httpObj.send(params);
    }
    catch (e) {
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Ready1() {
    try {

        var iFrame = crmForm.all.IFRAME_RelatedAttachments;
        var iDoc1 = iFrame.contentWindow.document;
        if (iDoc1.getElementById("gridMenuBar") != null)
            iDoc1.getElementById("gridMenuBar").style.display = "none";

    } catch (e) {
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3. Call the Notes() function on Onload event of Account Form, and you will see a Subgrid Displayed with Sorting on each column, and Refresh Button.


Tuesday, December 24, 2013

How to Create a new Guid CRM 2011 C# xRM Empty Guid or Null Guid

 How to Create/Generate a New GUID using Vb.Net, C# and Vb.Script

 Suppose i have got a guid in Query String like


http://localhost:3214/Default.aspx?id=9D2B0228-4D0D-4C23-8B49-01A698857709


or

like this

// Without Dashes
http://localhost:3214/Default.aspx?id=9D2B02284D0D4C238B4901A698857709










if (Request.QueryString["id"] != null)

string Id = Request.QueryString["id"];

Guid guid = new Guid(Id);

if(guid!= Guid.Empty)
{
  //Use id here to retreive the record.
}








Read More

Articles for you