1,408 articles and 9,624 comments as of Monday, March 1st, 2010

Friday, April 17, 2009

SharePoint Color Coded Calendar – The PayRoll Schedule

Update: Jim Bob has sent a 17 minute screencast of his solution which includes another way to assign colors.

After watching Mark Miller’s Screen-Cast, Color Code a SharePoint Calendar, I realized this was the perfect solution for transforming a payroll schedule on an Excel spreadsheet into a SharePoint Calendar to make it more visually appealing and user-friendly.

First Things First

Since I was beginning with a simple list of dates that was already color-coded, converting it to a calendar following Mark’s screen-cast was a snap!


Color Coded Calendar
Payroll Schedule in Excel

Of course, the first task was to create a SharePoint Calendar, in three easy steps:

Color Coded Calendar

1. Create

Color Coded Calendar
2. Create Calendar

Color Coded Calendar
3. New Calendar

Presto!

Color Coded Calendar
Basic Payroll Calendar

Show Me the Money

The basic calendar is nice and you can display lots of useful information using it this way. But the payroll calendar is something that folks will look at often and the most important question is When do I get paid?

So, let’s create some fields that will help us make Payday stand out, while providing color-coded information about some other important dates, as well.

Setting up the Columns

From the Payroll calendar we just created, click Settings > List Settings:

Color Coded Calendar
List Settings

Here, you will see I have already created some columns we will use to make our color-coded calendar.

Color Coded Calendar
Customize Columns

Let’s go through the basic columns and then we’ll expand on the more advanced ones:

  • Pay Period:  This is where we will store the number of the pay period. 1 is for the first payday of the year (though the pay period will most likely begin in the previous year), 2 is for the second, and so on. In our example, there are 26 pay periods per year, so when creating this column, I set a range of 1 to 26, just to avoid accidentally keying a wrong number.
  • Start Time and End Time: These come with the Calendar list and we’ll put them to use for our calendar, as is.
  • Title: This is the default field for every SharePoint list. We won’t be using it, so I made it not required.
  • Location and Description: Again, we won’t be using these, but they’re standard calendar fields that cannot be deleted.
  • Three other fields are standard calendar fields that will show up on the EditForm: All Day Event, Recurrence, and Workspace. For our purposes, we’ll use All Day Event and ignore the other two.

Advanced Fields

Now we move into the specific fields we’ll use to (a) make it easy for HR to update the calendar and (b) let their choices  be automatically color-coded so the employees can easily find the information they need.

DateType

In the spreadsheet above, we have two dates for the Pay Period: Beginning of Pay Period and End of Pay Period. We’ll combine these into one event and use the Start Time and End Time to show the beginning and ending dates.

Thus we’ll have three choices for DateType: Pay Period, Payday, and HR Deadline. (HR Deadline is the deadline for making any changes that will appear on that pay period’s payday.)

Color Coded Calendar
Column: DateType

We will be using the CHOOSE function to FIND a common letter in our DateType choices that is in a different location for each choice. Each of the choices shown has a lower case a, but that won’t work for us, since it is in the same location (the second position) for two of our choices: Pay Period and Payday. So, we’ll use the lower case d, which appears in each choice, but in a different position for each one.

Note: If your choices are different, you will need to look for a common letter to FIND. Alternately, multi-word phrases might allow you to search for a space, or you could force a difference by adding a number at the beginning of each item. If your choices are different lengths, you could use the length, rather than searching for a character or number. Finally, you could add a calculated field that assigns a number to each record which you would then use for calculating colors. (For each of these options see the following posts, or see the comments on Christophe’s post referenced below.)

Color and BGColor

Next we’ll create two calculated fields, based on the DateType choice.

When I examine the Excel schedule above, I see that the capable folks in HR have already chosen some colors to help them differentiate dates. I’m going to use those same colors, converting them to their hexadecimal values.

To find the color they’ve used, I opened the color palette in Excel to see what they’re using. The easiest way to do this in Excel 2007 is to right-click on the field and follow the on-screen menus. In order versions, you can get to this by going to the Font menu (Edit -> Font) and clicking the font-color drop-down.

Color Coded Calendar
Determining color values

Clicking on More Colors… will bring up the Colors dialog box.

Color Coded Calendar
Custom Color Values

Click on the Custom tab and look at the Red, Green, and Blue values. These are decimal values and we need to convert them to one hexadecimal value (White, for instance is #FFFFFF in hexadecimal) per color.

Each RGB (Red, Green, Blue) hexadecimal value can be separated into three pairs of two-digit hexadecimal values which represent the Red, Green, and Blue values, respectively. Looking at our first color above, we need to convert the Red, Green, and Blue values from decimal (128, 0, 128, respectively) to three two-digit hexadecimal values. A quick and easy way to do this is using the Calculator application in Scientific view.

Color Coded Calendar
Scientific Calculator (Choose View -> Scientific)

Simply enter your decimal value (128, in this case) and click on the Hex radio button.

Color Coded Calendar
Hexadecimal equivalent of Decimal 128

This is your Red hex value (and Blue, too, in this example). Zero in decimal is zero in hex, too. So, your RGB value becomes #800080 (the # indicates that this should be read as a hex value).

NOTE: The highest two-digit hex value is FF. Decimal is a base 10 counting system, meaning there are ten digits [0-9] used to make all of the numbers in it. Hexadecimal is base 16, meaning there are sixteen digits [0-9, then A-F] used to make all of its numbers.

Doing this for the other two colors, we see that HR has chosen #800080 for Beginning of Pay Period, #008000 for Payday, and #800000 for Payroll/HR Deadline (4PM). We’ll use those same colors for our calculated Color column.

FIND and CHOOSE

Now, we need to determine which color to assign to each row based on the DateType. As stated before, the common letter that has a unique position in each DateType choice is lower case d. We’ll use the FIND function to locate that exact position.

I always have trouble remembering which arrays are zero-based and which are one-based. If you’re like me, I recommend taking an intermediate step to determine what value each of your choices will return. So, before completing the next step, I recommend setting your Color Formula to: =FIND("d",DateType,1) and then looking at the data in a list view. In our case, this will show that the "d" is in the 10th, 4th, and 7th positions, respectively, for Pay Period, Payday, and HR Deadline.

To make it easy to visualize, in the next step this number will be the total number of commas that come before each respective color in the CHOOSE function.

NOTE: If you miscalculate and end up with fewer CHOOSE options than the highest value FIND returns, you will get an error that will show #VALUE in this field. Simply take off the CHOOSE and perform the FIND for each choice (as recommended in the intermediate step two paragraphs above) and recalculate.

Color Coded Calendar
Column: Color

How this works: The FIND function looks for d in the DateType choice. It will return this number to CHOOSE function which will then set the Color to the value in that position in the CHOOSE function.

For example, in "Payday," the d is in the 4th position, so FIND returns 4. The CHOOSE function then becomes =CHOOSE(4,,,,"#008000",,,"#800000",,,"#800080). The fourth position has "#008000" so that becomes the value of Color for this row.

BGColor

We’ll use pretty much the same formula for BGColor, only we’ll set the background a little lighter but in the same hue as the text and border.

A simplified look at RGBs will show us that sliding all three values up by a corresponding amount will result in a similar hue, but much lighter as they approach white (#FFFFFF). For each of our colors, the RGB values are either half-way "on" (128 or #80) or "off" (0 or #00). If the Color value component is half-way (#80 is half of #FF) on, we’ll set the BGColor to all the way on (#FF); if it’s off, we’ll turn it most of the way on (#CC).

So, we’ll copy and paste our Color Formula to our BGColor Formula then change 80s to FFs and 00s to CCs (notice that hex values are NOT case-sensitive).

Color Coded Calendar
Column: BGColor

Some Assembly Required

Now we can put all of these element together in such a way that Christophe’s (Path to SharePoint) Text to HTML script can make the Content Editor Web Part do the color-coding we need. (Follow the link to get the code.)

Color Coded Calendar
Column: Display

Breaking this down, we’re creating a box around our text using the DIV tags (this is what Christophe’s code looks for), using the same Color value for the text and the border; and using the BGColor value for the background color of the box. Within the DIV itself, we’re combining the DateType and the Pay Period number as the text shown on the calendar for our event.

Entering the Data

We’re entering a good amount of data into this calendar, so let’s make it a little easier on ourselves by creating an appropriate Datasheet View of our list data.

From our Calendar, click on the View menu and choose Create View

Color Coded Calendar
Create View

Choose Datasheet View

Color Coded Calendar
Create View: Datasheet View

Choose to only display the fields you need for quickly entering the data. (I set mine up as a Private view. You might want to walk your editors through setting up a similar view so they can enter the next year’s data without your help.)

Color Coded Calendar
Edit View: Datasheet View Shown from Edit View so that selected fields are at the top for screen capture.

Color Coded Calendar
Payroll Calendar: Datasheet View

One day’s entry will look like this (if you have ordered your columns this way):

Color Coded Calendar
Payroll Calendar Event (Pay Period event)

A Calculated Effort

Now, the default view for a calendar shows the Title, but we didn’t even fill that in. We want it to show our calculated Display field instead.

To that, we’ll go to the View menu and click on Calendar -> Modify this View:

Color Coded Calendar
View -> Modify this View

Scroll down to Calendar Columns and notice that the default fields shown for each record are the Title and Location fields, which we left blank.

Color Coded Calendar
Calendar Columns

We want to change those to Display and DateType, respectively.

Color Coded Calendar
Changing the Calendar Columns

Click OK.

Almost There

Once you have all of your data entered, take a look at your Calendar.

Color Coded Calendar
Payroll Calendar – NOT Pretty

Even though we have all the data just the way we want it… we still have to tell SharePoint that we want the Display field to be considered HTML. We do that using Christophe’s code in the Content Editor Web Part. (He deserves the traffic and recognition for his code, so I’ll let you go get it from him. Once you have it, I’ll show you what to do with it.)

The Final Touch

From your Payroll Calendar, go to Site Actions -> Edit Page

Color Coded Calendar
Edit Page

Click on Add a Web Part at the top of the screen:

Color Coded Calendar
Add a Web Part

Under All Web Parts, choose Content Editor Web Part and click Add:

Color Coded Calendar
Content Editor Web Part

Click on open the tool pane:

Color Coded Calendar
Open the tool pane

Expand the Layout section and check Hidden:

Color Coded Calendar
Hide the CEWP

Then click Source Editor… and paste Christophe’s code in the box and click Save.

Drag the Payroll Calendar web part to the top, so the Content Editor Web Part is last on the page.

Click OK.

Click on Exit Edit Mode

Color Coded Calendar
Exit Edit Mode

Voila!

Color Coded Calendar
Color-Coded Payroll Calendar

NOTE: If you want to include this calendar as a web part on another page, simply make sure you add the CEWP to the end of that page, as well, with the same code from Christophe.

Jim Bob HowardGuest Author: Jim Bob Howard
Jim Bob Howard is a web designer / web master in the healthcare industry. He has been working with SharePoint only since March 2009 and enjoys sharing what he has learned. You can email him at [email protected].

View all entries in this series: JimBobHoward-ColorCodedCalendar»
 

Please Join the Discussion

84 Responses to “SharePoint Color Coded Calendar – The PayRoll Schedule”
  1. Jim Bob Howard says:

    Thanks, Christophe! Sorry about that.

  2. Jayesh says:

    Hi,
    we can use following code using jQuery to replace <a> innerHTML instead Christophe’s code

    if(typeof jQuery=='undefined'){
    	var jQPath = 'https://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'
    	document.write('');
    }
    
    $(document).ready(function(){
    $("a:contains('
    
  3. Frank says:

    I work for a military hospital and use the Outlook calendar because of the color codes. We are currently using WSS3.0 for our Intranet and each department and clinic use also use the Outlook calendar. We will upgrading to MOSS in June 2009. Our ‘main calendar’ is what the staff is able to view. I would like to be able to set one color as the ‘standard’ for the hospital. Here is the list we use.
    APFT/CTT = Green, Hospital = Orange, Schools = Gray, Meeting/Conference/VTC = Yellow
    Hope you can help.
    Thanks,

  4. Jim Bob Howard says:

    Dear Frank,

    I have sent Mark three more short screencasts of ways to implement the color-coded calendar when your choices don’t have a common letter in a unique position.

    He’s planning to run them as a series. Stay tuned.

    Blessings,
    Jim Bob

  5. Christophe says:

    Frank, I have just released a “formula generator”. It is basic but may help you get started:
    http://www.pathtosharepoint.com/HTMLcc/default.aspx
    Note that in your specific example you may have to remove the “/” in your categories as they are special characters in html.

  6. Flora says:

    Is it the same with Excel web page, if we want to change the color of the column

  7. cloudno9 says:

    Great, thanks for this step by step instructions.
    I followed all the steps and at the end I have payroll calender. Only thing I am having trouble is “HR Deadline” it still shows me <DIV style….” instead of color. Pay Period and Payday is working fine. Can you tell me what am I missing?

    Regards,
    T.I.A.

  8. Jim Bob Howard says:

    cloudno9,

    I would need to take a look at how that one may be different.

    If all of the rest are working fine, that tells me something is being messed up in the HTML. Post the full HTML that is being displayed and I can help you trouble-shoot it.

    Blessings,
    Jim Bob

  9. Cloudno9 says:

    Here is the code that I am using to convert that calculated field text into html…

    //
    // Text to HTML
    // Feedback and questions: [email protected]
    //
    var theAs = document.getElementsByTagName("a");
    var i=0;
    var AContent = " ";
    while (i < theAs.length) {
    try {
    AContent = theAs[i].innerText || theAs[i].textContent;
    if ((AContent.indexOf("<DIV") == 0) && (AContent.indexOf("") >= 0)) {
    var tempDIV = document.createElement ("DIV");
    tempDIV.style.cursor = "pointer";
    tempDIV.innerHTML = AContent;
    theAs[i].innerHTML = "";
    theAs[i].appendChild(tempDIV);
    }
    }
    catch(err){}
    i=i+1;
    }
    

    and this is what I am getting on my calender for HR Deadline….

    HR Deadline: 1

    Let me know if you need something else.

    Regards,

  10. Jim Bob Howard says:

    It’s the code around HR Deadline that I need to see. If you pasted it with the “<DIV …” around it, it didn’t come through. Try emailing it to me instead.

  11. Webape says:

    I too am having the same issue: everything works but the HR Deadline. that is drawing html code instead.
    If you spot the issue, let me know.

  12. Webape says:

    One more clue: when I set the HR Deadline to be an all day event it works.

  13. Jim Bob Howard says:

    cloudno9 and Webape,

    Skip the “DIV” portion of the tag and post what it’s giving you in the rest of the tag, starting with “style=’border…”

    Blessings,
    Jim Bob
    [email protected]

  14. Webape says:

    This is what is showing for the HR Deadline
    if I set it to 4:00 PM

    Style='border:1px #800000 solid; padding: 5px; margin: 0px;color:#800000; background-color:#ffcccc;'>HR Deadline:1
  15. Jim Bob Howard says:

    And when you change it to All Day Event, what do you get?

  16. Webape says:

    I get the colored box as in your example minus the “4:00 PM” above it.

  17. Jim Bob Howard says:

    Click on that item and post what is in the Display field (minus the DIV again)

  18. Webape says:

    Style=’border:1px #800000 solid; padding: 5px; margin: 0px;color:#800000; background-color:#ffcccc;’>HR Deadline:1

  19. Jim Bob Howard says:

    Webape: Email me: [email protected].

    I want to check something. Perhaps we can solve this offline and then just post the solution. ;)

  20. Dan Wilcox says:

    Very useful, Jim Bob. Thank you for taking the time to post!

  21. Jim Bob Howard says:

    Another way to calculate the right colors, especially if you don’t have a common character in a unique location.

  22. eric nordlund says:

    This is great, I’ve been trying to figure out how to do this for a while now. I almost tried to buy an application to accomplish this goal.

    Is there a way to get rid of the extra whitespace at the bottom of the calendar after this is done?

  23. Jim Bob Howard says:

    Eric, I don’t have whitespace at the bottom of mine. Have you hidden the CEWP?

    If not, try this…

    1. From Site Actions choose Edit Page
    2. On the CEWP, click edit -> Modify Shared Web Part
    3. In the Edit pane, expand Layout
    4. Check the Hidden box
    5. Click OK
    6. Click Edit Exit Mode

    HTH

    Blessings,
    Jim Bob

  24. Ken Johnson says:

    Jim Bob,

    Many thanks for posting this solution!!

    KJ

  25. eric nordlund says:

    Thanks Jim Bob, I did do that, but it didn’t update immediately so I didn’t see it. Works great!

  26. cloudno9 says:

    any update on this yet?

    Thanks

    Webape: Email me: [email protected].

    I want to check something. Perhaps we can solve this offline and then just post the solution.

  27. Neeti says:

    This is working very well.
    Is there a way to change the color based on the current date? So, if there is an activity planned for tomorrow, this should show in Amber. If the activity is planned for today, it should show as Red.

  28. Jim Bob Howard says:

    Neeti: Great question. I will work on a solution and post my findings in the next few days.

  29. Jim Bob Howard says:

    Neeti,

    Two questions:

    1. Are colors only based on date and not a type of event?

    2. What color for items more than one day in the future and in the past?

    Blessings,
    Jim Bob

  30. Neeti says:

    Jim,
    What I am looking for is that the color should depend on the type of event for all future and past events.
    But as soon as the date when the event is expected to happen arrives, the color becomes red [#ff0000] or better still would be, if it could start flashing…
    I day before the event is due to happen, the color should become amber [#ffc000].

    So, if an event is scheduled to happen on 05-May-2009, then on 04-May-2009, it should become amber, and on 05-May-2009, it should become Red.

    Thanks
    Neeti

  31. Jim Bob Howard says:

    I see. I’m going to have to punt on this one for a time. If you’re needing a quick answer, I recommend looking into Christophe’s suggestions on working with [Today] here, here, and here.

    If you get it working, I would love to see the solution you found!

    Blessings,
    Jim Bob

  32. owen says:

    Hi

    I found that I needed to recreate the CEWP with null values, move it to foot of page (below Calendar), exit web page, then go back and paste in a fresh copy of Chrisptophes code to get it to work for single day events – multi day events worked OOTB

    web development is so much fun : )

  33. Jim Bob Howard says:

    Webape and cloudno9, take a look at owen’s solution and see if that doesn’t help.

  34. Cloudno9 says:

    Hi Jim,
    Single day event works if its a full day event. but when you have the event from (lets say) 12:00pm to 2:00pm than it shows the “div” code for that event.

  35. owen says:

    Further:

    people make similar comments to mine in Christophes blog and it will work – exact reasons for multiple failures unknown.

    It works for all meeting lengths for me – minutes to multiple days.

    several pieces of advice:
    1. follow Chrisptophes advice in comment 1 to get the code from the right place.

    2. I found that it didn’t work a couple of times until I used his copy to clipboard at head fo code (vs highlight and copy)

    3. I use the Hide weekends code from Christophe as well – had to get the day highighter working first (under the calendar), then added the hide weekend afterwards – ie keep it simple to start with, and finally

    4. Check your column code – in my case it had to do with nested ‘ and ” – passed the sharepoitn acceptance but didnt display right.

    Good luck

  36. Scott says:

    This is a great solution for a MOSS shortcoming! I got our organization calendar working with one minor problem. If I click on the week view in the calendar any events that are repeating (recurrence) the title does not show up. The only thing in the time block is the circular recurrence symbol. All other events display normally in the week view. In the month and day view all events display perfectly.

    Any suggestions?

  37. That’s a great question for Christophe.

    Christophe, how could your code be modified to change the way the time and recurrence icon are displayed? As it is, the time and recurrence icon are displayed above our calculated box. In the week view, the colored box doesn’t show up at all.

    Thoughts?

  38. eric nordlund says:

    Love the calendar. Is there a way to put a key on there so users can know what the colors mean? I think I could put some little color boxes in the description bar at the top, but I can’t figure out how to get the bar to display html. My code just shows up in the bar as code.

  39. Christophe says:

    I have published an update that should address the issues with intraday and recurring events:
    http://pathtosharepoint.wordpress.com/2008/11/15/sharepoint-calendars-color-coding-hover-effects-etc/
    I plan to publish a more complete update in a couple weeks.

    @eric: simply add the key as html. See a similar example in the following post:
    http://pathtosharepoint.wordpress.com/2008/09/29/another-example-of-progress-bar/

  40. Scott says:

    Christophe: I tried using the updated code you you linked to above on 15 May and it did not work at all. After the failure I reinserted the old code and it worked as before, month and day view perfect, week view does not show the time or title on recurring, only the circular recurring symbol. I am trying to get my group to adopt the color coding, but without the week view showing all events properly I am getting pushback. Appreciate any help you can give me.

  41. Christophe says:

    Scott: did you remember to replace the DIV tag with a SPAN in the formula, as explained in my updated post? Feel free to send me your formula:
    [email protected]

  42. Did anybody figure out why some people are getting DIV code for hourly appointments and it works for the all day events, I think Cloudno9 was having this problem. I changed my code to SPAN, and got the same issue. Thanks for any help on this in advance.

  43. david says:

    I added the code and followe dthe video a few times but i keep getting the code on the cell instead of the color cell. do i need to turn javascript on the SP server, or somehting else

  44. Dustan Roed says:

    Here’s a neat trick…

    In your display column, you can determine an all day event (ADE) by checking TEXT([start time], “h:mm”)=”19:00″. If that is true, you can render a DIV tag, which gives the nice stretched-out color we are seeking. If it fails, use a SPAN tag for non-ADEs, but you may want to play with the formatting a bit by setting a standard height and width.

    I would like to find a way to hack the surrounding DIV in sharepoint for non-ADEs in week and day view. Anybody got any ideas?

  45. Bas says:

    I’m testing this solution, but I have problems with normal calendar entries – they are showing as code. Only all day events works properly.
    When I check a web page source of calendar before any changes was made I can see that in normal calendar entries I didn’t have any after but they exists in all day events – maybe this is a problem.

    What can I check to make this solution run properly?

    Regards

    Bas

  46. owen says:

    Bas
    check Christophes blog on the same subject. I left an entry there explaining how I had to recreate the calendar anew with the colour coding as it just wouldnt work with an existing calendar.

    Software is just like this sometimes (it wasnt just caching at the browser/server either as far as I could tell – just wouldnt ‘take’ the new design and display HTMl properly).

    It will work – persist : )

  47. Bas says:

    Colour coding script from http://pathtosharepoint.com/ works ok :))
    Thank You very much :))

    Best regards

  48. Scott S says:

    For the code showing on the hourly events I resolved it by adding to the JavaScript. I had it recognize the B tag (bold around the time) just like the A and TD tags. Works perfect now.

  49. Oscar says:

    Hi,

    I got this working fine with the DIV tags on the Month view, but when I switch to a day view or week view, I just see the html code instead of the tags.

    Is everybody else that has this working seeing the color shading correctly on the Day view and Week view?

Trackbacks

Check out what others are saying about this post...
  1. [...] SharePoint Color Coded Calendar – The PayRoll Schedule [...]

  2. [...] SharePoint Color Coded Calendar – The PayRoll Schedule [...]

  3. [...] comments from readers on the EndUserSharePoint.com blog. Several months ago, Jim Bob Howard posted an example using my method. His post offers detailed step by step explanations, and is very popular. However, a few readers [...]

  4. [...] April, Jim Bob Howard provided us with a very popular solution for calendars, SharePoint Color Coded Calendar – The PayRoll Schedule. This was based off of Christophe Humbert’s work on Path to [...]




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!