Dev Help

Cross Domain Access to HTTP Handler using jQuery Ajax

We can access Http handlers directly from a regular AJAX call, if they are in the same domain. However it is not the case if handler is hosted in a different domain. One solution is to use JSONP (the “padding” around the pure JSON).

JSONP pass the response from the server in to a user specified function, return the response as JSON, but also wrap the response in the requested call back.

In order to use JSONP, server has to support JSONP. The client tells the server the callback function for the response. The server then return the response as JSON, but also wraps the response in this callback function.

HttpHandler sending the response in the format expected by JSONP.

public class AtomHandler : IHttpHandler
  /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the System.Web.IHttpHandler interface.
  /// <param name="context"> A System.Web.HttpContext object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests .< /param>
  public voidProcessRequest( HttpContext context)
   string jsonString= "{'Title':'What Will Brand Engagement Look Like in 2020?','Summary':'When it comes to brand engagement, 5 years will seem like a lifetime.','UpdatedDate':'4/23/2015 4:27:46 AM +00:00','FeedType':'MBD - Marketing'}" ;
   string jsonp=context.Request["callback"];
   if (! String.IsNullOrEmpty (jsonp))
    jsonString = jsonp + "("+jsonString+")";
   context.Response.ContentType = "application/json";
  /// Gets a value indicating whether another request can use this instance.
  public bool IsReusable
    return false;

jQuery JSONP request to get data from handler.

var loadAtomData=function() {
  try {
      url: "http://<server>/AtomTest/AtomHandler.ashx",               
      type: "GET",
      dataType: "jsonp",
      jsonp: "callback",
      contentType: "application/json; charset=utf-8" ,
      success: function (responseData, txtStatus, jqXHR) {
        console.log( "The response is" , responseData);
      error: function (responseData, txtStatus, errThrown) {
        console.warn(responseData, txtStatus, errThrown);
        alert( 'JSONP failed - ' + txtStatus);
  } catch(e) {
$(document).ready( function() {

Web browsers let scripts from a webpage to access data from a second page, if both have the same origin (URI scheme, hostname and port). JSONP works since browsers do not enforce the same-origin policy on <script> tags.

How to Create a Custom View for SharePoint 2010 Survey

As you all know creating a custom view for SharePoint in-built survey list is not there by default. But this is a required feature in some cases. For example if you want to filter survey responses by an answer to a particular question, then having a view with that question is handy. 

So here is a workaround:

01. First of all find the survey ID. We can do that by navigating to survey settings and Find query string parameter “List” from the browser URL.


02. You won’t find ‘Create View” option in the ribbon or anywhere, but can access that page by directly accessing from the URL. So visit “Create View” page using the URL:

http://<server>/_layouts/ViewType.aspx?List=<List ID from previous step>

03. In order to create a new View, click on “All Responses” link from “Start from an existing view” section.

04. In the Create View page, provide a “View Name”, select Columns and set any other settings. Click OK.

That is it! View can be accessed from the URL: http://<server>/Lists/<survey name>/<view name>.aspx

“Detailed” is the custom view that I created and shown in the above screenshot.

xrm.CreateQuery() - Invalid 'where' Condition

“Invalid ‘where’ condition. An entity member is invoking an invalid property or method.”

I came across above error, while I was working on a LINQ query to retrieve a set of records from a CRM 2013 custom entity. It is a CRM 2013 online environment and I was using XrmServiceContext to retrieve data.

Even though it appears to be that I have specified an invalid property, I found out below line is causing the issue.

Where(d => d.nav_expirationdate.HasValue && ...

It turns out that LINQ to CRM implementation expects two values in each condition and CRM Property must be on the left hand side. Otherwise where clause will simply crash.

Code that will Crash with Invalid 'where' condition exception:

this.xrm.CreateQuery<nav_myrequest>().Where(d => d.nav_expirationdate.HasValue && ...

Code that will Work without an error:

this.xrm.CreateQuery<nav_myrequest>().Where(d => d.nav_expirationdate != null && ...

CRM 2013 – Plugin Registration Error

Error: Plug-in assembly does not contain the required types or assembly content cannot be updated.

This error was occurring when I try to update a Plugins assembly using Update Assembly window of the CRM SDK PluginRegistration.exe. I was able to register this same assembly couple of hours ago and now without major changes I’m unable to register it.

Problem turned out to be that another developer has updated the same plugin assembly with extra plugin classes added to the assembly. I was getting this error; since I did not have those extra plugins in the assembly I was trying register.

This is something to note about when registering plugins for the testing purpose in a shared environment without check-in the code.

Full error I got:
Unhandled Exception:
System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Plug-in assembly does not contain the required types or assembly content cannot be updated.
Detail: <OrganizationServiceFault xmlns="" xmlns:i="">
  <ErrorDetails xmlns:a="" />
  <Message>Plug-in assembly does not contain the required types or assembly content cannot be updated.</Message>
    <ErrorDetails xmlns:a="" />
    <Message>Plug-in assembly does not contain the required types or assembly content cannot be updated.</Message>
    <InnerFault i:nil="true" />
    <TraceText i:nil="true" />
  <TraceText i:nil="true" />

Server stack trace:
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Microsoft.Xrm.Sdk.IOrganizationService.Update(Entity entity)
   at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.UpdateCore(Entity entity)
   at Microsoft.Crm.Tools.PluginRegistration.RegistrationHelper.UpdateAssembly(CrmOrganization org, String pathToAssembly, CrmPluginAssembly assembly, PluginType[] type)
   at Microsoft.Crm.Tools.PluginRegistration.PluginRegistrationForm.btnRegister_Click(Object sender, EventArgs e)

Simple JQuery Tooltip Plugin for SharePoint Page Content Sections – Colortip

Tooltip control is a great way to display additional information in web sites without making the web page larger and improving user experience and usability.

There are so many jQuery plugins that we can find, like in this list. Most of them require us to add supporting file like JS, CSS and images to the developing web site in order to use the tooltip control.

One of the common approaches used in jQuery plugins is to call to a JavaScript function, passing few parameters including tooltip content whenever we want to display a tooltip. Those tooltip plugins won’t much helpful when comes to use them in SharePoint Page Content sections since some html segments like scripts will get striped in page content sections upon saving.

We can use either SharePoint 2013 script editor webpart or Content Editor webpart with a referring text file as an alternative. But neither of them gives the flexibility of editing content as Page Content sections provide.

JQuery plugins like Colortip comes in handy in this type of situation.

Step 1:
Download ColorTip plugin form the tutorialzine site. Upload colortip-1.0-jquery.css and colortip-1.0-jquery.js file to a document library. There are no images to be uploaded.

Step 2:
Add the following script section in the page using a Script Editor webpart or any other mechanism. This includes the references to the plugin resources (update as necessary), popup trigger and additional condition to prevent plugin from running/modifying content in edit mode of the SharePoint page.

$(document).ready( function() {
   var inEditMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
   if(inEditMode !="1") {
  $( '.mypopup[title]' ).colorTip({ color: 'blue'});

Step 3:
Include anchor tags where the popup needs to display. Title is the popup text. Class ‘mypopup’ is used to trigger the popup.

Lorem Ipsum is<atitle="Popup on dummy text"class="blue mypopup">simply dummy text</a>of the printing and typesetting industry.

This is how it looks: 

Note: For SharePoint wiki pages, in order to find if the page is in Edit mode from JavaScript, use following condition:

var inEditModeWiki = document.forms[MSOWebPartPageFormName]._wikiPageMode.value;
if(inEditModeWiki =="Edit")
  // trigger popup
  $( '.mypopup[title]').colorTip({ color:'blue'});