Category: Development

Various articles, public code and other developer resources.

Adding Events to SharePoint Fields

SharePoint Logo[This article should be considered deprecated.  The code represented has been improved, extended and made available as the DP_SharePoint Function Library.  All future effort will be applied there.]

The first article in this series dealt with obtaining a reference to a SharePoint field in Add and Edit forms.  One of the most common reasons to head down this path is to add custom validation to fields.  Often this requires adding events to (in the case of most fields) the onchange or (in the case of buttons) the onclick events of the fields.  Simply setting the event handler directly would work, but will eliminate any currently enabled handlers (such as those defined internally to SharePoint).

Instead I created two functions to abstract the standardized addEventListener() and (for older IE browsers) the attachEvent() methods.  They accept a reference to an HTML element (in this case a SharePoint form field), an event type and a function name to call when the event is fired.  The first adds an event to the passed element and the second (which is included for balance but which I’ve honestly never actually used) removes it.

(more…)

Obtaining a JavaScript Reference to a SharePoint Field

SharePoint Logo[This article should be considered deprecated.  The code represented has been improved, extended and made available as the DP_SharePoint Function Library.  All future effort will be applied there.]

I’ve been digging further and further into the bowels of SharePoint.  It’s not a pleasant place to dig.  At my company end-users and team-site owners are prohibited from doing any back-end development.  Additionally, due to various political issues, there are currently no available processes to contract for such work (although you can be added to an ever-growing waiting list).  The only development path open to site owners is client-side JavaScript.

On the team-site I manage one of the most used features is a custom list cataloging enterprise Incidents managed by the team.  Each incident is logged with information about the applications affected, the team engagement times and many other pieces of information.  The list feeds business customer reports and generates performance metrics for upper management.  With over 20 people on the team the quality of information can be rather shaky.  It would benefit greatly from some simple validation and a few points of automation.

(more…)

Sunday Coding Humor

Having been doing more development recently and revisting code abstraction components that I’d written years ago but that are still proving insanely useful I imagined this little dialog in my head.  I hope that I’m not the only coder out there that can relate to this.  First when you’re building the component:

Writing a new component is like giving your furture self a thumbs up and big, goofy grin.  Hey, older self, I think you'll need to this again!  You're aces!

Followed potentially years later when you’re still finding uses for it:

Using an old component to solve a new problem is like seeing your past self give you a thumbs up and a big, goofy grin.  Thanks, younger self, I did need to do that again!

Happy coding!

Update of DP_DateExtensions to Correct Parsing Error

A slight update to my JavaScript date extensions, DP_DateExtensions, is available for download.  This release addresses another issue related to paring of “AM” and “PM” indicators.  The gist of the problem was that the parser was transversing Noon and Midnight.

I had two bugs.  When I encountered a PM indicator I was simply adding 12 to the “hours” value if it were less than 13.  Of course 12 noon plus 12 hours is midnight the next day.  I needed to check for “less than 12” not “less than 13”.  However I also wasn’t taking any action if the indicator was AM – which left 12 AM as “12”, or noon, in the resulting 24 hour clock representation.  If the indicator were AM I needed to check if the hours were 12 and set them to zero if so.

(more…)

Formatting Excel Links for Import into SharePoint Lists

SharePoint LogoSpent way too long figuring this out today and thought I’d do an entry so that I’d remember it.  To set the stage my team manages emergency situations and restoration of service for over 800 enterprise applications.  As you might expect we have a SharePoint list of these applications with basic information about them.

One of the values is a unique enterprise-wide code that we’ll call the “AppCode”. One of the first things we do when a problem is reported is find that AppCode code for the application and search the system of record for detailed information about the application, the support, ownership, etc.  This isn’t difficult but it does take precious seconds.  Instead my plan was to create a link directly to the application profile in our list.

(more…)

New Version of DP_DateExtensions and Some Esoteric Integer Parsing

[Actually the “new” version is nearly a month old at this point but I forgot to do an entry to announce it.]

There’s a new version of my JavaScript date extensions, DP_DateExtensions, available.  This release fixes a significant, but interesting bug brought to my attention by Kevin Warnke.  He noticed that, sometimes, when you parsed a date with a 12-hour clock the resulting time was simply wrong – often off by weeks.  This, for some reason, annoyed him.

After digging I did find (and fix) the problem.  As you might expect to parse a time with a 12-hour time you need to take the time given and add 12 to it (if “PM”) to convert it to a 24-hour clock.  To do this I did some simple addition:

Hours = Hours + 12;

This worked fine in most cases.  However if “Hours” had leading zero, like “04” JavaScript treats this as a string and would result in “0412” rather than “16” as you might expect.  However when adding the value to a date JavaScript happily treats it as a number – so instead of adding 16 hours to my new date this resulted in adding 412 hours – or over 17 extra days!

Although there are many ways to fix this I decided to force the conversion by using the parseInt() function like so (the “10” indicates that you want to parse the value as base 10):

Hours = parseInt(Hours, 10) + 12;

This fixed the problem nicely.  In the end, a pretty silly error that I should have caught much sooner.

New Version of DP_DateExtensions

I’ve just uploaded a major update to my venerable (6 years-old!) JavaScript date extensions DP_DateExtensionsThis was a near-complete rewrite of the component and like most hard (and some great) work it started with an error.

The question Alexey Vassiliev (who reported the bug) asked me is “how many days are there between March 1, 2012 and March 31, 2012?”  Assuming Midnight for both dates the common sense answer is, of course, 30 days.  My component however was returning 29 days… why?

(more…)

Lotus Notes Tribunal, Exhibit 001-K: “Notes Takes a Moment to Go Pants-crapping Crazy”

A Depressed Press SeriesPart 11 of 15 of The Lotus Notes Tribunal

Lotus Notes is a crime against humanity. In exhibit 001-K we see how it’s unpredictability is a danger to children and pets.

There’s an “Actions” menu in Notes.  In it there’s a promising option called “Fax Address Helper”.  I like help.  With Notes I often need help.  So I click on it.

Whoa!  What the hell is that?  A mostly blank window with an off-centered blob of red text?  Some serious sh*t must have gone down, eh?  This error message must be especially important for Notes to make such a spectacular departure from all user-interface guidelines, right?  Right?!  Wrong.

The message clearly states that “You must be in a mail memo to use this feature…..” (the five periods must be for extra-special, super-duper emphasis).  A normal application would have simply greyed out or removed the “Fax Address Helper” from the actions menu when you were not in a memo.  Not our defendant however: Notes would prefer to deceive.

The rest of the content gets even better.  We get an “OK” button (already highlighted as the default) but are instructed not to click on it.  If we do so, we’re told, our highlighted item will be marked “unread”.  This means a developer spent time adding a note to this message rather than spending the time fixing the problem.  That makes sense.  Lots and lots of sense… if you’re evil.

Lotus Notes Tribunal, Exhibit 001-J: “Folder Tree”

A Depressed Press SeriesPart 10 of 15 of The Lotus Notes Tribunal

Lotus Notes is a crime against humanity. In exhibit 001-I we see evidence that perhaps Notes maliciousness may in fact be the result of psychosis.

Notes loves to mix-metaphors.  It loves it so much that it will often mix them multiple times on the same element.  Consider the folder tree.  This is the most fundamental, most basic navigation tool provided by Notes.  And it gets things horribly wrong.

Note that most items represent a physical metaphor: folders, toolbox, trash can, etc.  Many of these items carry that metaphor forward into the usage of the element.  Click on “Tools” item and the little toolbox opens.  Click on a folder and the folder opens?  Well, most of the time.  Notes confuses and distracts us in this case by only “opening” folders which contain other folders.  Folders that contain only memos are left closed even when clicked.  Why?

Furthermore note that the icon for “Views” represents a windows preferences dialog.  Note also that when selected it opens like a folder  Dialog boxes don’t open like folders in the real world, do they?  However other physical items like the trash can never open.

The only logical excuse for getting something so basic so fundamentally wrong is pure malicious intent or mental illness.

TiVo Sucks

My premise is simple: TiVo sucks.  I will defend it, but I do want to make one thing clear: TiVo sucks, but having used TiVo, Comcast and DirectTV DVRs I feel confident in saying “so does everything else.”  This will not be an exhortation to switch brands of DVR but rather a lamentation of the state of an industry so dominated by what’s become a mediocre product.

(more…)