Author Archives: chamindasomathilaka

Having fun with non-MS tech for person stuck in MS tech for more than decade

I have being experimenting with few non-MS tech just to taste the world out there which I haven’t seen for last decade. I know I’m not going win that world in a day or two, or may be not during rest of my life. But I need to fill-up void in my brain that may open up more happier paths. Specially for a person who code for pleasure.


It is great, when what you do for living also earns you pleasure. I have tasted that pleasure with MS tech for last decade without even at least peeping alien waters of Open Source, or more crowd contributed tech.

So for So good

My love for JavaScript has being one of the key factors made me standout among most of my fellow coders throughout. So started with Javascript’s next big thing Node.JS. Believe me it is fun. I am sure I haven’t felt this way for at least for half a decade since I played with per-release version of ASP.NET MVC.


this is so easy… click click click with few nexts my Node engine running. Oh no…npm (Node Package Manger) is my best friend now. For some reason, I have never being a fan of Nuget anyway. It is doing everything for me. One highlight is that I couldn’t get away from MS tech fully as I again stuck with Visual Studio Code as the my editor. I tasted Brackets as well.  “forever” got me running all the time even if I crash in the middle.

My love for JS is extended to storage too. With Mongo let me store my JSON without any hassle. Of cause mongoose  giving me helping had in between.

Day dream is over

All of a sudden here I am back in real world seeing some of the things in Node.JS in new .NET word with .net Core.

So all my friends out there like me, try NodeJS, may be Ruby On Rail… believe me will not regret on time spent.


Striping apostrophe from beginning and end of string using JavaScript

For me the JavaScript only provides most primitive set of capabilities that are required by most developers. That is one reason what made jQuery a popular framework. 

To do even simple thing like trimming a sting with a know character is not possible unless you write your own routine. What I have demonstrated here is addition of a function to String type to remove single quotes (an apostrophe) from beginning and end of a string.

String.prototype.unquoted = function (){return this.replace (/(^’)|(‘$)/g, ”)}

var str=”‘hello'”


Enable custom ribbon button only if user has permission to edit selected item

The simplest and way to hiding a SharePoint Custom action in a ribbon(/or anywhere) for users whom doesn’t have item edit permissions is, using “Rights” attribute of “CustomAction” element.  Comma separated set of rights can be specified here so that the cumulative rights set will be formulated by ANDing all different individual rights. All possible Rights available are SPBasePermissions


RegistrationId=”10001″ Sequence=”20″
Rights=”EditListItems,AddListItems” >

“Handle with Care “ – SharePoint Lists with Large lists

Here are few key things to remember when implementing SharePoint applications with high volumes of data.

    1. Never try to override List View Threshold. Keep it to 5000 as it is by default.
    2. Try avoiding increase of “List View Lookup Threshold”, keep it as 8
    3. Apply indexes to relevant columns. Be mindful about the content of column before adding indexes
    4. Use out of the box webparts as much as possible. Utilize parametrized list view webparts, connected webparts etc to achieve advance filtered listings
    5. Make sure to use indexed columns as much as possible in CAML queries
    6. Make sure to prioritized CAML query filters depending up on number of items filter out by each clause
    7. Avoid using People fields for CAML query filtering (anyway those are not index-able)
    8. Don’t rely on lookup columns heavily.
    9. Make sure you filter only the required set of list items
    10. Try using SPListItem.GetItemById whenever an Items being retrieved
    11. Avoid using SPQuery to make queries, instead user ContentIterator so that there will be less locks in DB
    12. If required, use caching(possibly ASP.Net Cache) when custom code is being used
    13. Off load processing from server as much as possible


      Some more tips by Amit Phatak at

Invoke server side code on SharePoint custom ribbon button in background

It is happen to be SP2010 and above not allowing Custom Ribbon Actions not allowed to have ControlAssembly and ControlClass to execute server side code (which happen to be in SP2007).  By the way this is possible with some other locations like context menu even with SP2010.

But there are few workarounds that can make up to this. Three of such workarounds have being clearly showcased by Naddem Yousuf on his blog. However I wanted to have a button which will trigger a update in background while the user remains on the List Form. So I used Nadeem’s 1st option with slight modification to JS event handler. Here is my modification.

    var iframe = document.createElement(“iframe”);
    iframe.setAttribute(“style”, “display:none”);
    iframe.setAttribute(“name”, “hiddeniFrame”);

    var form = document.createElement(“form”);
    form.setAttribute(“method”, “post”);
    form.setAttribute(“action”, pageUrl);
    form.setAttribute(“target”, “hiddeniFrame”);

Here I am creating a hidden iframe and using it as the target of the form so that everything from the control response will be hidden from the form.



“Unable to get property ‘defaultDialogWidth’ of undefined or null reference” on SharePoint Modal Popup

Error message “Unable to get property ‘defaultDialogWidth’ of undefined or null reference ” was thrown when trying to load modal popup on a page where very less of CSOM related script loaded.  In case you haven’t set width or height it is suppose to pick the default value for height and width.  It happens to be all the default values used by most JSOM are loaded from a resource file. 

To be precised, the js library that has the method to load the modal popup  “SP.UI.Dialog.js” has a dependency to the “SP.Res” namespace from where it will pick all the defaults from. 

                                       LoadSodByKey(“sp.res.resx”, function(){
                                          LoadSodByKey(“dialogUI”, function () {

                                            SP.UI.ModalDialog.showModalDialog({url : ‘/sites/abc.aspx’, title: ‘My Page’});         

Simple but may not be the perfect solution for this it forcefully loading the sp.res.resx resource file content with “LoadSodByKey”.


Update Business Data Catalog Throttle Config with PowerShell

function UpdateBusinessDataCatalogThrottleConfig($maximum, $defaultVal)
    Write-Host "Update Business Data Catalog Throttle Config." -ForegroundColor cyan
    $bdcProxy = Get-SPServiceApplicationProxy | where {$_.GetType().FullName -eq (‘Microsoft.SharePoint.BusinessData.SharedService.’ + ‘BdcServiceApplicationProxy’)}

    $dbRule = Get-SPBusinessDataCatalogThrottleConfig -Scope Database -ThrottleType Items -ServiceApplicationProxy $bdcProxy

    Set-SPBusinessDataCatalogThrottleConfig -Identity $dbRule -Maximum $maximum -Default $defaultVal