Friday, February 17, 2012

Get time from a SharePoint Date / time field via jquery

In creating a list form for a lending application, the customer had the following requirement:
The return date must be after the departure date.

That means not only does the date have to be checked, but the hour as well.
Getting the date from a field is really easy in jquery because you can refer to the title of the field:
var date = $(":input[title=’DateField1’]").val();
But getting the hours and minutes proved to be another task. Since the date-time control is a complex control (having a lot of components) not all components have their own title to refer to.
If you look at the source code for a date/time control however, you can see the hours dropdown has the same ID as the date picker, but it has the word “Hours“ added to it.
Same goes for the minutes dropdown with the word “Minutes”. This allows us to get the time like this:
  //create a string variable to put the time in
  var sTime = "";
       
  // get the ID from the date control
  var dDateID = $(":input[title='"+field+"']").attr("id");
  //get the value from Hours by referring to the id + Hours
  var dDateHours = $(":input[id='"+ dDateID + "Hours" +"']").val();
  sTime = dDateHours;
  //get the value from Minutes by referring to the id + Minutes
  var dDateMinutes = $(":input[id='"+ dDateID + "Minutes" +"']").val();
  sTime += dDateMinutes;
      
  alert(sTime);
Note that the Hours field also has a “:” in it! If you are doing mathematical equations, it is better to put it in a date type or take the substring:
  dDateHours = dDateHours.substring(0,2)
Creating a function that gives you the date and time
I put the code in a separate function that needs the control title as an argument and returns the date and time as a Date.
Keep in mind that I am using the DD/MM/YYYY notation on my date fields.
If you are using the MM/DD/YYYY notation you need to change the depday and depmonth variables.
function getdatefield(field){
  var ddate = $(":input[title='" +field+ "']").val();
  // date looks like DD/MM/YYYY
  var dday = ddate.substring(0,2);
  var dmonth = ddate.substring(3,5);
  var dyear= ddate.substring(6,10);
  var dDateID = $(":input[title='"+field+"']").attr("id");
  var dDateHours = $(":input[id='"+ dDateID + "Hours" +"']").val();
  //delete the “:”
  dDateHours = dDateHours.substring(0,2)
  var dDateMinutes = $(":input[id='"+ dDateID + "Minutes" +"']").val();
  var departuredate = new Date(dyear,dmonth-1,dday, dDateHours, dDateMinutes,0);
  return departuredate;
}
Check if one DateTime is bigger than the other
This allows a dateTime check (to see if one date is bigger then another) to be very easy:
function PreSaveAction(){
  // check for return date > departure date
  if(getdatefield("DateField1") > getdatefield("DateField2")){
    alert("DateField2 must be bigger then DateField1!");
    return false;
  }
}
I put the check in the PreSaveAction, because I am checking it before the user submits the form.

Monday, February 13, 2012

Are employees rejecting SharePoint ?(Melcrum internal comms hub - case study)

An article on Melcrum, a networking site on strategic communication challenges, drew my attention via a note on Yammer.

They asked 2 communication experts to argue whether or not SharePoint is being rejected by employees.

Sam Marshall, director of ClearBox Consulting Ltd says: Yes
- Employees still use email attachments
- Team sites are often document graveyards
- Low adoption rates on blogs / My Sites
- Employees have to be active content participants instead of passive readers
- Employees are used to working with email, attachments, network drives
- SharePoint is highly complex
- User interface is unpleasant
- Training is too much on “how” instead of “why”
- Behavior issues are rarely directly addressed at launch time
- Employees are given building blocks instead of a solution to their problem

Camilla Herrmann, internal and digital communications consultant says: No
- Collaboration is about people working together, not just the use of a tool
- Email attachment habit is hard to break
- There is an appetite among Gen Y workers for something more then just email
- Organizations need to send a strong message that collaboration is a good thing (example of forum on the intranet)
- People search is very powerful
- Social workplace is still new – organizations need to take small steps via (example of comments on news items)
- Views can save your employees hours of work
- If properly planned, well supported and actively launched, SP can be a ground-breaking application

Both parties have excellent points and in my opinion a lot of them are true.
But the best quote is one I found in the comments:
SharePoint is just a platform. If it is not properly launched (with a good training and support) and people are rejecting it, who’s fault is it ?

You have to admit: email and attachments are darn easy to use and send! But you have great tools that can support you in saving emails in SharePoint libraries and emailing the link!

A lot of the points Sam makes is simply Change Management, the factor most overlooked in SharePoint projects:
You have to tell people WHY and HOW SharePoint is going to make their life easier.
Why do you need to add metadata? To find your document faster.
Why do you have version management ? So you can immediately see which one is the current version, without losing the other changes people have made.

Implementing SharePoint is not like installing a new email-system: The technology part is just 20%.
You need rules. You need internal marketing. You need SharePoint Champions. You need governance. You need user training. You need vision.

If you are going to use a new platform with new capabilities, you have to show people the added value and hold their hand when they take their first steps. People are out of their comfort zone, and it is your job to make them feel comfortable again in their new situation.
Don’t just give them Lego Blocks, but tell them what the blocks can do, how they can connect and most important: give them some ideas on what they can create with it.
Don’t just give them an engine and some wings. Show them pictures of an airplane. Tell them what cool things the airplane can do for them. In no time, they will build their own airplane, with the functionalities they need to do their job.

There is a role for everyone here:
- Implementation partners / IT have to deliver great performance and superb support – no one wants to use an applications that constantly fails
- Coaches / Champions have to be around to help people build their space ships or castles or fire stations
- Communication department must start deliver the possibilities to help people speak their mind and enable blogs / ratings / comments
- Managers must act as leading examples: start blogging / tweeting / Yammering / insert your tool here / and show people that it is ok to think, that it is ok to speak your mind, to think out of the box
- Change managers have to focus on Why this tool is getting used, and show the direct /indirect benefits for the employees!
There is tons of great information online for all roles: youtube is filled with SharePoint how-to movies, technet info on how to keep your SharePoint running smooth, marketing/PR information to build interest, managers with blogs, …

Start with the small steps, people will grow and start taking giant leaps in no time!

Friday, February 10, 2012

Get / Set the UI language code via Jquery / Javascript

I was searching around how to get the SharePoint language for a user (the language of SharePoint when a user is logged in) for a multilanguage project.

John Liu helped me out on the msdn forum:
alert(_spPageContextInfo.currentLanguage);


To set the language for a user (make sure you have the required language packs installed) – via Mike Smith:
<button onclick="OnSelectionChange(1036)"> French </button>
<button onclick="OnSelectionChange(1033)"> English </button>


Get your locale code here

Thursday, February 9, 2012

Hide SharePoint WebPart header menu dropdown arrow and selection checkbox

Working on a dashboard page for users with limited possibilities, I had to disable the close and minimize webpart functionality.
Instead of just hiding the functions, I chose to have a minimalistic view and hide the arrow.

The webpart header consist of following parts:

tr class =ms-WPHeader (which is the header)
td class = ms-wpTdSpace (white space)
td class = ms-WPHeaderTd (the actual title)
td class = ms-WPHeaderTdMenu (which has the dropdown arrow and menu)
td class = ms-WPHeaderTdSelection (which has the selection checkbox)
td class = ms-wpTdSpace (white space)

So if you want to hide the arrow, you need:

<style type="text/css">

.ms-WPHeaderTdMenu {display:none}

</style>



If you want to hide the selection box, you need:

<style type="text/css">

.ms-WPHeaderTdSelection {display:none}

</style>

Wednesday, February 1, 2012

Hide the SharePoint Search field

If you want to hide the SharePoint 2010 search box on a specific page, you can add a content-editor webpart to the page with following code:
<style type="text/css">
.ms-sbcell {
        DISPLAY: none
}
</style>

This will hide the search box.

Fun and clear movie about SharePoint Governance

The people from 21Apps just released this fun movie. It takes about 6 minutes and it explains the 5 key pillars of SharePoint Governance. Great informational piece for people who are just starting on the subject!!

Wednesday, January 11, 2012

soon: uCertify review 70-667

The people from uCertity asked me to write a review on their 70-667 preparation kit.
Initially this looks great, but people who are close to me know that I now have much more important stuff going on in my life then to blog right now ;)

And for those who don't know yet, my girlfriend gave birth to a gorgeous little girl, Charlotte.