Many times, while consulting with our clients, we discuss the free SharePoint application templates from Microsoft, sometimes dubbed the “Fabulous 40” or the “Fantastic 40”. There’s some great functionality available for relatively little effort – yet another example of the Pareto principle, or the 80/20 rule.
If an enterprise is looking to create a simple SharePoint-based service request ticketing system, the Help Desk template (also included in the IT Team template) provides a good place to start. It includes some custom input screens, management views, and KPIs. It’s a fairly common element of SharePoint 2007 initial rollouts.
Recently, I was asked to install the solution for a client that was trying out the system to replace an outdated low-end ticketing system. They’d asked for some simple page customizations to the new ticket input ASPX page. The client noticed that the initial data form didn’t default the “requester” to the current user, and asked why. After a little experimentation and research (including the SharePoint Team Blog), I added a simple JavaScript that does the trick.
The script uses a technique to push a callable function into an array of functions to fire for the page’s onLoad event (see the SharePoint Team Blog for an explanation of why). In any event (no pun intended!) we grab a tag to the initial people picker field and pull the user name from the page top nav element and push in into the control’s innerHTML value.
|
<script type="text/javascript"> _spBodyOnLoadFunctionNames.push("fillDefaultValues"); function fillDefaultValues() { var requestorInput = getTagFromIdentifierAndTitle("div", "", "People Picker"); var currentUser = getUserDisplayName(); requestorInput.innerHTML = currentUser; } function getUserDisplayName() { var tags = document.getElementsByTagName('a'); for (var i=0; i < tags.length; i++) { if(tags[i].innerText.substr(0,7) == 'Welcome') { return tags[i].innerText.substr(8,tags[i].innerText.length); } } } function getTagFromIdentifierAndTitle(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; } </script> |
Just take this code and drop it at the beginning of PlaceHolderMain on the NewForm.aspx page or your customized version. (Its a best practice to customize on a copy of the original page instead of the original.) Hope you find this useful …have fun!