I’ve seen a few questions out on Twitter in the past few weeks on how to change SharePoint page behavior based on querystrings passed in an URL. While the context for this question leads to many possible alternatives (filter web parts, custom web part, xslt, js, etc…) I found that the advice I was giving in most cases was “if you just need something quick (and dirty), then just inject some javascript. It seems though that arn’t many easily findable tutorials around for how to do this, so I decided to write this article. Please note that this is NOT the best way to accomplish every possible problem scenario taking into account security, maintainability, performance, etc… It does however work which makes it a viable tool to add to your bag of tricks in my book. Also, I’m going to present the code samples here using straight javascript, but you could certainly streamline some of the code by using other frameworks like jQuery.
So to begin, the first thing we need is some javascript that can read the querystring and parse it into a JS array for us to use later. There are a ton of these snippits all around the web, here’s the one I use:
function getQueryStringArray() {
var qs = location.search.substring(1, location.search.length);
var args = qs.split("&");
var vals = new Object();
for (var i=0; i < args.length; i++) {
var nameVal = args[i].split("=");
var temp = unescape(nameVal[1]).split('+');
nameVal[1] = temp.join(' ');
vals[nameVal[0]] = nameVal[1];
}
return vals;
}
Ok, so now we need a function to “find” the control we’re after on the page so that we can do stuff to it (like set it’s value, or hide it). I have found that the easiest way of doing this is to look for an element that has the right TagName (e.g. “input”), the right SharePoint Datatype (e.g. “TextField”), and SharePoint FieldName (e.g. “Title”). The TagName is easy, since that’s the actual tag of the element in the DOM. The SharePoint Datatype is actually appended to the END of the ID attribute, so a little parsing will be required. Finally, the SharePoint FieldName is the value assigned to the TITLE attribute of the element. It would be cool if we could just key off this alone, but obviously on any given page you can’t guarantee all items will have a unique TITLE attribute. Here is an example of an element that you may want to target on a form’s NewForm.aspx or EditForm.aspx pages:
<input name="ctl00$m$g_beee8c5c_b1a1_4356_84f5_
462f43dc6b4a$ctl00 $ctl04$ctl09$ctl04$ctl00$ctl00$TextField" type="text" maxlength="255" id="ctl00_m_g_beee8c5c_b1a1_4356_84f5_
462f43dc6b4a_ctl00_ctl04_ctl09_ctl04_ctl00
_ctl00_TextField" title="RelatedCT" class="ms-long" />
And here is an example function that you could use to parse the DOM and return the target element based on these three pieces of information:
function getFieldElement(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title &&
(identifier == "" ||
tempString.indexOf(identifier) == tempString.length – len
)
) {
return tags[i];
}
}
return null;
}
// So for Example, to return the target element above we’d make the following call
var theElement = getFieldElement(“input”, “TextField”, “RelatedCT”);
Once you have a handle to the element, you can do all sorts of things with it. For exmaple, setting it’s value, making it readonly (if you don’t want to the user to change it’s value once you’ve populated it from the querystring), or even hiding the whole field all-together. Here is an example function that can does all of the above (note, slight changes are required to work with non-textfields such as checkboxes, dropdowns, lookup lists, etc.)
function processField(theFieldName, theValue, setReadOnly, setHidden) {
var el=getFieldElement("input", "TextField", theFieldName);
if(el!=null) {
if(theValue!=null) { el.value=theValue; }
if(setReadOnly) { theField.readOnly=true; }
if(setHidden) {
//Set the whole table row to not display (includes label and all)
theField.parentElement.parentElement.parentElement
.style.display="none";
}
}
}
Ok, now that we have all of our helper functions ready to go, we need to put them all in a JS file and drop that where it can be accessed from the form pages (or where ever you plan to do the injection). Possible places to consider are a document library (if you don’t have physical access to the server) or 12/TEMPLATE/LAYOUTS/1033 (if you do have physical server access). The nice thing about the later location is that you can either directly link to the script from anywhere via /_layouts, OR you can use the <SharePoint:ScriptLink> tag to have SharePoint automatically generate a non-client-cachable link to the script. You will also need to use the _spBodyOnLoadFunctionNames.push method on the pages to get SharePoint to correctly insert you “injected” code into the proper spot in the whole JS Init of the pages (remember there are all sorts of things SharePoint pages need to run before we get to your injected code). When I edit/customize a list’s NewForm.aspx or EditForm.aspx page I generally like to inject this bit of code at the very top of the PlaceHolderMain content placeholder. Here is an example that links to my saved helper functions from above, pushes a function onto the OnLoad chain, and then set’s the values and visibility of 3 fields from the querystring.
<asp:Content ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>
<SharePoint:ScriptLink runat=”server” Name=”ListFuncs.js”/>
<script type=”text/javascript”>
_spBodyOnloadFunctionNames.push(“processFields”);
function processFields() {
var vals=getQueryStringArray();
processField(“TaskList”, vals[“List”], true, false);
processField(“TaskID”, vals[“TaskID”], true, true);
processField(“OriginalAuthor”, vals[“author”], false, false);
}
</script>
[ … rest of the form …]
</asp:Content>
While this article certainly was an exhaustive tutorial on how to do this form of SharePoint customization, I’m hoping it will be enough to get some of you started in the right direction and experimenting.
It’s been about a year since I first wrote about micro-blogging within the context of Web 2.0 technologies that could provide value on the corporate intranet portal. Since that time, the explosion platforms such as Twitter have highlighted the value of this type of communication in an open public context. Other major platforms such as Facebook have revamped their primary information aggregation user interfaces (the “wall”) to be decidedly more micro-blogging-like, proving that this type of rich “status update” stream can be valuable within smaller communities as well. Niche players have emerged such as Yammer and Present.ly to fill the micro-blogging gap in the current best-of-breed intranet portal solutions. I’ve decided to take many of the lessons learned in the past year, primarily from our corporate use of both Twitter and Yammer to describe some of the benefits that micro-blogging can allow an enterprise to realize and capitalize upon.
Before I get ahead of myself, for those of you that may not be familiar with micro-blogging, it is essentially a way of sharing small bits of information usually from one-to-many (think of an email distribution list). Most micro-blogging platforms represent these “small bits of content” in streams. There is generally an author’s stream (everything you’ve posted) and also your aggregated stream which will be a filtered view of everyone else’s streams. Many platforms, like Twitter, use the concept of “following” that provides the main filtering mechanism on your twitter stream, but other filtering concepts such as by keyword, group, hashtag, etc. can be used. Note here the main difference between a micro-blog and an email system: in the email system it is the author that decides who will receive the messages; in a micro-blogging system, it is primarily the recipients that have control over what they receive. This plays an interesting role in the dynamics of spam, relevancy, and attention—but that is a post for another time. One of the best introductions to micro-blogging may be Common Craft’s “Twitter in Plain English” (note that this is not enterprise-focused).
The rest of this article will cover some of the benefits of micro-blogging in the enterprise including:
- Mass Content Distribution
- Expert/Connector Location
- Trust Building / Culture
- Knowledge Management / Relevancy
- Training / Information Radiation
- Idea Exchange / Suggestion Box / Employee Voice
Mass Content Distribution
There are many times within an enterprise when you want to get a piece of information out to either all of the employees or a subset group of employees quickly. Today the primary way of accomplishing this task would be an email distribution list (either company wide or a department list). This works fine, except today our email boxes are overwhelmed with chatter both from the inside and certainly from outside (even with modern spam filters). It is quite possible that a critical email sent from the CEO company-wide may not get read by some for hours or days. This is not to say that a micro-blog will fix this problem completely or eliminate the need for “author-based recipient control” that an email provides, however, the fact that recipients have greater control over what they choose to listen to also means that will pay special attention to what they’ve opted into.
Micro-blogging also has a distinct advantage over group emails when the intent of the communiqué is to elicit a discussion amongst the recipients. Email “reply-to-all’s” are incredibly difficult to follow, especially as the replies create split branches and varying “quoted” chains below them. In fact, the next version of Outlook even contains a feature to “mute” an email thread you’ve been placed on so that you don’t have to bother reading them :)
Expert/Connector Location
By reading about what people are talking about in a stream you can start to get a better feel for what they are expert in. This might include knowing who would make a good target for your pick-up game of basketball tomorrow evening, but more importantly, it will tell you who is knowledgeable, helpful, and passionate about various areas you need to complete your job! Most micro-blogging systems also let each author create self-edited profiles that are searchable for areas of expertise, experience, and interests. Some also have creative features that tag users (either by system analysis of posts, or by other users opinions of them) and track various “reputation” scores allowing those searching for expertise to get potentially more relevant and unbiased filter criteria for the so-called experts.
Connectors are people within the enterprise that connect people to others. While the gist of the above paragraph is that a micro-blogging platform may reduce the need for these individuals making it easier to find experts within the enterprise, it will never eliminate it. This is because as most seasoned networkers will tell you, these connections are built upon shared trust, which takes time to establish (see next section and also my article “Discovering Your Relationship Topology”). These connectors play a critical role in how your business gets done and should be the targets of both succession planning and process optimization strategies. Micro-blogging platforms easily expose these individuals through follower counts, interaction counts, and reputation scores.
Trust Building / Culture
At first the idea of micro-blogging is crazy to people. I hear “why would anybody care about what I’m eating for lunch?” when explaining twitter to first time users (note of course a typical prompt in an enterprise micro-blog is “what are you currently working on?” not “what are you currently doing?” like with Twitter). However, think about how you interact with people in real life. When you see a colleague on a Monday morning do you immediately ask them “what’s our revenue forecast for the week?” or do you ask them if they did anything interesting over the weekend? Oh you went downtown to that new restaurant with your wife? How was it? What did you have to eat?
The point is that to build trust between individuals (which collectively can be extrapolated to an entire corporate culture) we absolutely MUST have these types of trust-building small-talk conversations to establish personal connections which can then lead to more meaningful relationships and deeper discussions. For more details on this idea of trust building, pick up Chris Brogan’s new book Trust Agents or Shel Israel’s Twitterville.
Knowledge Management / Relevancy
Since micro-blogs are content streams themselves, they by default become a knowledge repository, which as long as items of interest can be located, either by keyword or metadata search, then this alone qualifies it as a viable knowledge management strategy. However, this is not really the main way micro-blogging can benefit a larger knowledge management strategy. We already have big huge systems with taxonomies and formalized metadata for capturing and archiving documents. And we also have big huge systems that capture our structured line of business data. These two pillars are certainly enough to capture any and all data – sometimes to the point at which it has no chance of ever escaping (snark).
These systems do a good job of storing the information, and some are even pretty good at helping you find it again. However, once you start amassing a lot of it, relevancy becomes a problem. That is, how quickly can I find the piece of information that is most relevant *to me* based on my specific need and ability level to consume the information? Be honest, if you could, you’d probably just go ask the internal subject matter expert and have them direct you to the best information. What micro-blogs allow (as well as other social media technologies like social-tagging and folksonomies) is that it provides a way for individuals to point at (with a hyperlink) subjectively high quality content which provides a means to store “tacit relevancy” metadata about the most important topics within your enterprise.
Micro-blogs also do a better job of capturing conversation context (the who, when, what aspects) around content than many other mechanisms, thus shedding light on the sometimes elusive “why” or intent questions. A very important point to micro-blogs and knowledge management that I want to underscore is that sometimes the content IS the conversation, but often the conversion is about OTHER content (hyperlinked in the post) and thus serves an important role in a larger enterprise content management strategy.
Training / Information Radiation
New hire training can be accelerated by Micro-blogs especially in the realm of “how we do things around here”. Often we find that it takes longer for new folks to internalize this aspect of their job than the actual technical or business skills required to execute the mechanics of their job. This is especially true if you have either a unique culture (positive) or a dysfunctional one (and lord help you if you have a uniquely dysfunctional one).
Seeing folks from across the enterprise share their content and helpful “finds” will also aid in the continuous learning and training for all employees. In Alistair Cockburn’s Agile Software Development he describes information radiation and osmotic communication as the natural and efficient way knowledge travels across a co-located project team performing software development. Micro-blogging platforms extend this concept so that the co-located aspect (both physical and temporal proximity) is no longer a necessary component for this knowledge sharing.
Idea Exchange / Suggestion Box / Employee Voice
Micro-blogging has the effect of giving all employees a voice and you’d be surprised at the wonderful ideas and tips some have to share that otherwise would not be surfaced either due to their personality or perceived “place”. Employers are sometimes afraid of giving their employees this voice, but most of the fears are not well founded. One of these fears is that employees will use the platform to spread negative thoughts to their peers. Generally, if these ideas are not based in truth, you will see other employees “setting the record straight” in a much more transparent fashion than you would get in hallway/water cooler talks. Also, people will generally not be dramatically nasty in a micro-blogging setting since their comments are recorded, attributed to them, and usable against them if disciplinary action is called for. If the ideas are based in truth, then you can be thankful that you have an early warning mechanism for problems in time to take proactive measures to address them.
Another fear employers often have is that it feels like they are giving up some measure of control. This is actually true to a degree, but it is only by giving up control that you gain trust. This is the crux of the cultural change happening right now both inside and outside the enterprise. The shift from traditional advertising (corporate controlled) to social media (consumer controlled) epitomizes this statement. Those new employees that have grown up in the digital age are now starting to move into high level leadership positions within many organizations and fill out the majority of the workforce. They understand and demand this change in dynamic so companies would do well to embrace it. For more reading on this topic, please pick up Dan Tapscott’s Grown Up Digital.
There are probably other areas of benefit that I’ve missed here (let me hear about them), but I based these 6 primary areas on actual observations over the past year. For each of the above areas I have more specific anecdotes I can share, and may do that over the next few months. Other than mentioning a few platforms at the beginning of this article, I tried to stay away from a technical/tools discussion, but obviously once you are sold on the need for micro-blogging within the enterprise or at least willing to experiment, there are a universe of choices in the form of platforms and add-on products to platforms to consider.
Please tell me about your experiences with micro-blogging within your enterprise!