CRM 2011 Debug: How to Debug Plugins using Profiler

One can debug CRM plug ins without connecting to CRM server or without remote debugging.

 

Here are the steps as in how you can use Profiler for debugging plug ins:

   1>     Connect to CRM using plugin registration tool of March SDK 2012.

 

   2>      Click on Install Profiler

         

 

   3>     You will find a new node attached to registered plugins “Plugin Profiler”.

 

 




   4>     Select a plug-in step and click Profile to enable profiling.

 

 

 

5>     Then start your plugin from MSCRM i.e if your plugin is on update perform  update operation and download the error file.

6>     Then in Visual Studio attach to process “plugin registeration.exe”. Add the breakpoint  from where you would like to debug.

 

 

7>     Then click on Debug in plugin registration tool.

 

 

8>     In Profile location provide the path of the error log of the plugin.

 

9>     In Assembly location provide the dll of the plugin from which you got error.

 

10>     Then select the Plugin class from Plug-in. This drop down will contains all classes present in the dll.

 

11>     To start debugging just click on Start Plug-in Execution.

 

 

CRM 2011 JS: Insert FetchXml into subgrid chart's view using javascript

I went digging around on the net to find examples of this and did find serveral that got me in the right direction.  But I still seem to be missing something.  I think what I'm doing wrong is assigning the fetchxml to the subgrid rather than the chart's view in the subgrid.  Can anyone tell me how to fix this?  Thanks for all your help!

Here is the error message, not very helpful...

 

code:

function UpdateSubGrid() {

    var accountSales = document.getElementById("SalesSummary");

    if (accountSales.readyState != "complete") {

        setTimeout('UpdateSubGrid()', 1000);

        return;

    }

    var accID = Xrm.Page.data.entity.getId();

    alert(accID);

    var accountNum = Xrm.Page.getAttribute("jensen_accountnumber").getValue();

    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>";

    fetchXml += " <entity name='account'>";

    fetchXml += " <attribute name='jensen_yeartodatesales' />";

    fetchXml += " <attribute name='jensen_yeartodateplan' />";

    fetchXml += " <attribute name='jensen_lastyearsales' />";

    fetchXml += " <attribute name='name' />";

    fetchXml += " <filter type='and'>";

    fetchXml += " <condition attribute='statecode' operator='eq' value='0' />";

    fetchXml += " <condition attribute='accountnumber' operator='eq' value='";

    fetchXml += accountNum;

    fetchXml += "' />";

    fetchXml += " </filter>";

    fetchXml += " <order attribute='name' descending='false' />";

    fetchXml += " </entity></fetch>";

    alert(fetchXml);

    accountSales.control.setParameter("fetchXml", fetchXml);

    accountSales.control.refresh();

}

 

 

Here is the Account form with the subgrid that has the chart in it, highlighted:

This chart us showing ALL accounts rather than being filter to the account I'm in.  The new fetchXml that I'm trying to assign it did not get set.

Posted by Cory Bonallo

 

CRM 2011: Steps to deploy custom aspx page

In CRM 2011 its not required to deploy it in ISV. We need to create a new web site. Firstly publish the solution to “/InetPub/wwwroot/<PublishFolderName>” or publish and copy the published files to the same path. Follow the below steps:

1. Goto IIS. Create a new website. Need not change the ApplicationPool. This should create a new ApplicationPool in the same name as the website. Specify a different port number which is not used by either CRM or any other websites. In Physical path give Published foler path in wwwroot(/InetPub/wwwroot/<PublishFolderName>).

2. Goto ApplicationPool and for the new ApplicationPool change the following properties:

  •  .Net FrameworkVersion – v4.0
  •  Managed Pipeline Mode – Classic (previously it will be Integrated)

3. Right click the ApplicationPool and Open advanced Settings. Change the Identity property to “Network Service”.Thats it:) done deploying..

You can check it by selecting ur aspx page and select Browse. Make a note of the url from the IE window.

 

CRM 2011: Attach OnClick event to all fields on the CRM Form and Passing querystring to silverlight web resource in the footer

 

/*

Attach a click event to all fields on the CRM 2011 form.

There is a silverlight page on the footer of the form. On click of any field i need to pass the schema name of the source field(which raised the event) to the silverlight page.

Using the Xrm properties we cannot get the control of a control in the footer.

Here I had to pass a dynamic parameter to the querystring of the silverlight web resource and the ‘setData’ method also cannot be used directly.

 

On load of the form I attached events to all label fields on the form.

For the web resource on the footer there is a property called ‘control’ which gave access to the ‘setData’ method.

Initially I dont want any data parameter to be passed. So in the web resource properties i passed an empty string as data parameter.

This allowed me to change the data parameter dynamically.

*/

 

function AttachAttributEvents()

{

    var attribs = Xrm.Page.data.entity.attributes.get();

    var attribName = "";

    for (var i in attribs)

    {

        attribName = attribs[i].getName();

        if (attribName != "")

        {

            document.getElementById(attribName + '_c').onclick = function ()

                { //Attach events to the label of each attribute

                    var Elt = window.event.srcElement.parentElement.id;

                    var EltName = Elt.substring(0, Elt.length - 2);

                    document.getElementById("WebResource_FieldInfo").control.setData(EltName); //Pass Data parameter to the web resource

                };

        }

    }

}

 

CRM 2011: Dynamically change sub-grid fetchXml - left navigation pane

In CRM 2011 account entity there are 2 left navigation links called Open Activities and Closed activities. When we select these, the sub-grid populates activites associated with the related contacts also. To filter them based on the regarding field we can use javascript to pass the fetchXml dynamically and change the view.

For this you need the IFrame id in which the grid gets loaded.

To get the IFrame control:

var frame = document.frames["areaActivitiesFrame"].frameElement;

Bind “onreadystatechange” event for the Iframe:

frame.onreadystatechange = function () {
if (event.srcElement.readyState == “complete”) {
BindGrid(“Open”, frame);
}
};

Get grid control and pass the fetchXml

function BindGrid(state, frame) {
var currentId = Xrm.Page.data.entity.getId();
var currentName = Xrm.Page.getAttribute(“name”).getValue();
var fetchXmlStr = getFetchXml(currentId, currentName, state);
fetchXmlStr += getFetchXml(null, null, state);
frame.contentWindow.document.getElementById(“AppGridFilterContainer”).style.display = “none”; //To hide filter
frame.contentWindow.document.getElementById(“newViewSelector”).innerText = state + “Activities:”; //Change the text
frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers_SavedNewQuerySelector”).style.display = “none”;
frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers”).control.setParameter(“fetchXmlForFilters”, fetchXmlStr);

frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers”).control.setParameter(“fetchXml”, fetchXmlStr);
frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers”).control.refresh();

}

After getting the grid contol you can make any changes you want in the grid: changing the header text, hiding elements inside the grid…

Thanks.

 

Microsoft Dynamics CRM 4.0 :Developing a Basic Silverlight Application

This section walks you through the basic steps necessary to create a project inside Microsoft Visual Studio 2008, using Microsoft Dynamics CRM data and then displaying within Microsoft Dynamics CRM. In this project, we use the Visual Studio add-in for Silverlight. In this foundation project, we build a UI component using a VS.NET project and a data access component using WCF:


1. Open Visual Studio 2008.

2. Select File, New, and then Project.

3. In the Project selection window, select Silverlight Application (as shown in Figure 1).

Figure 1. Project selection in Visual Studio 2008.

4. Click OK.

5. In the Add Silverlight Application dialog box, select Automatically Generate a Test Page to Host Silverlight at Build Time. For production release, you can attach this to an existing ASP.NET application. By default, this will create two files in the Solution Explorer:

  • App.xaml is a file used to declare shared resources such as data grids and various style objects. The code behind this file is used for handling global events such as Application_Startup, Application_Exit, and Application_UnhandledException (see Figure 2).

    Figure 2. Show sample app.xaml.
  • Page.xaml is the default file created. Typically, this is replaced with the new Silverlight page (see Figure 3).

    Figure 3. Show sample page.xaml.

Create a WCF project in the same solution. WCF is used as the communication layer for the Silverlight application. WCF supports asynchronous connections between the Silverlight application and the backend data sources. Figure 4 shows the communication sequence between the client and the backend when a user is viewing CRM notes on the Account page using Silverlight and all the steps in between.

Figure 4. Sample of the process to extract data for Silverlight.

1. Right-click the solution and create a new WCF project.

2. Click Add.

3. Select New Project.

4. Select WCF Service Application, as shown in Figure 5.

Figure 5. Select WCF Service Application.

Once the new project is attached to the solution, build the necessary connection to the CRM system, whether it is using web services or direct SQL access. Some organizations prefer direct SQL access for reading, whereas other organizations prefer to use the web services.It is recommended to use Microsoft Dynamics CRM web services to read and write data. However, if your application is only reading data, you can access the SQL views and access data very easily.

Proxy Credentials for web requests

TO make WebRequests from behind a firewall, we need to attach a proxy object to our request.

    
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
//Create proxy credentials
ICredentials credential = new NetworkCredential(uid, password, domain);
//Create proxy server. byPassListArray is a string array of local ip's to bypass
IWebProxy proxyServer = new WebProxy(proxy,true,byPassListArray,credential);

request.Proxy = proxyServer;
request.Credentials = new NetworkCredential(Uid,Password);

example code snippet:

string query="http://www.feedster.com/search.php?type=rss&q=" +srch+ "&sort=date&limit=100";
WebProxy proxyObj = new WebProxy("10.10.249.19", 8080) ;
NetworkCredential networkCredential = new NetworkCredential("yourname", "yourpass") ;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(query) ;
proxyObj.Credentials = networkCredential ;
req.Proxy = proxyObj ;
// this request uses the default credential set--
req.Credentials = System.Net.CredentialCache.DefaultCredentials ;
// or we can create unique new credentials:
//request.Credentials = new NetworkCredential(Uid,Password);

XmlDocument doc = new XmlDocument();
System.Net.HttpWebResponse resp =(HttpWebResponse)req.GetResponse() ;
doc.Load(resp.GetResponseStream());
XmlDocumentFragment frag = doc.CreateDocumentFragment();
XmlNode nod=doc.SelectSingleNode("//channel/item");




REGEX expression for HTML Tag cleaning

C# code for replacing either a specific tag, or removing a series of potentially malicious tags from an HTML string:

 
using System.Text.RegularExpressions

// Replace BODY tag with "<div id="advert/">" (for later replacement with ad code, for example):
strContent = Regex.Replace(strContent, @"</?(?I:BODY)(.|\N)*?>", "<div id="advert/">");


//Malicious script: replace any and all of script / body /embed / object / frameset / frame / iframe / meta / ling /style with "")
strContent = Regex.Replace(strContent, @"</?(?I:SCRIPT|BODY|EMBED|OBJECT|FRAMESET|FRAME|IFRAME|META|LINK|STYLE)(.|\N)*?>", "");

Regular Expression to convert URL to Hyperlink


using System.Text.RegularExpressions;
//this will turn all urls in the input parameter string sInput into
HTML hyperlinks

public string ConvertURLsToHyperlinks(string sInput)
{
return Regex.Replace(sInput, @"(\bhttp://[^ ]+\b)", @"$0");
}



Print contents of IFRAME from parent window

 
/* Jscript: Print contents of IFRAME from parent window */


<script language=JavaScript>

function CheckIsIE()
{
if (navigator.appName.toUpperCase() == 'MICROSOFT
INTERNET EXPLORER') { return true;}
else { return false; }
}


function PrintThisPage()
{

if (CheckIsIE() == true)
{
document.ifWorkspace.focus();
document.ifWorkspace.print();
}
else
{
window.frames['ifWorkspace'].focus();
window.frames['ifWorkspace'].print();
}

}

</script>

In the parent window, just put a link or button to call the PrintThisPage() method:

<a href="javascript:PrintThisPage();">Print This Page</a>

</pre>