1,804 articles and 15,081 comments as of Saturday, June 4th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Thursday, June 4, 2009

Color-coded SharePoint Calendar with Lookup DateTypes

In my previous articles on color-coded calendars, the colors have been calculated based on a Choice field. But what if you need more functionality to, say, require approval for certain calendar entries like Personal Vacation.

Creating a Lookup Table

To add approval functionality like this (which is beyond the scope of this article), you’ll want to create a new table that has the names of your date types along with other fields you will need for a workflow, like this:

Color Coded Calendar with Lookup

 

Create: Absence Type

A list will allow you to associate other information with your date type, for example, to use in a Workflow

Once you’ve created the list of date types, you can then add a Lookup column to your calendar so your users can choose from your list and your workflow can handle any back-end processing that needs to occur for your specific business needs.

 

Color Coded Calendar with Lookup

Lookup column

Absence Type is getting its information from the new list by the same name

"Houston, we have a problem…"
When it comes to color-coded calendars, we run into a problem with this method. Now that our date type is a Lookup column, SharePoint won’t let us include it in our color calculations.

Color Coded Calendar with Lookup

Error

Lookup columns are not supported in formulas

We have a couple of options:

    • We can let SharePoint Designer do the calculation for us, which will keep the color choices hidden from the end user, OR
    • We can give the end user control over the color as well as the types of absences

For the purpose of this article, we are going to explore the second option, which will still involve using SharePoint Designer.

Assigning Colors

Let’s start by adding two fields to our Absence Type list: Color and BGColor. Both should be a single line of text with a max length (optionally) of 7. We’re going to be storing our hexadecimal values here.

Color Coded Calendar with Lookup
Absence Type – with two new fields

 

We will need to make some changes to our calendar columns as well. Color and BGColor will no longer be calculate fields. We can’t change them to the column type we want so we have to delete the existing ones and re-create them the way we want them.

Color Coded Calendar with Lookup
Customize – Color, BGColor, Absence Title, and OldDateType will be filled in by a Workflow

Notice we’ve added two extra fields: Absence Title and OldDateType. Go ahead and add these, each as a Single line of text. We’ll need these when we get to our workflow.

Hiding System-calculated Fields

It would be confusing to the user for us show these fields on our edit and display forms, so let’s hide them.

    • From the calendar, click on Settings -> List Settings

Color Coded Calendar with Lookup
Settings -> List Settings

    • Under General Settings, click on Advanced settings

Color Coded Calendar with Lookup
General Settings -> Advanced settings

    • On Content Types, click Yes under Allow management of content types?

Color Coded Calendar with Lookup
Allow management of content types? – Yes

    • Click OK
    • You will now see a Content Types section on the List Settings page
    • Click on Event

 

Color Coded Calendar with Lookup
Content Types section – Click on Event

    • For each field you want to hide, click on its Name

 

Color Coded Calendar with Lookup
When managing Content Types, columns can be Required, Optional, or Hidden

In our example, we don’t need Location, Color, BGColor, Display, Absence Type, or OldDateType to be visible

    • On Column Settings, under This column is:, choose Hidden (Will not appear in forms)

 

Color Coded Calendar with Lookup
This column is: Hidden (Will not appear in forms)

    • Click OK
    • Repeat for the rest of the columns

 

Color Coded Calendar with Lookup
Hidden columns

    • Go back to Settings

 

Color Coded Calendar with Lookup
Click on the Settings breadcrumb

For simplicity, you can now turn the management of content types off and your hidden columns will remain hidden.

    • Under General Settings, click on Advanced settings
    • On Content Types, click No under Allow management of content types?
    • Click OK

 

Color Coded Calendar with Lookup

Absences – New Item

Color and Display columns are hidden, as well as the unused column, Location

Checking Our Progress

Once we’ve entered some dates, we can go to our calendar to see the progress we’ve made so far.

Color Coded Calendar with Lookup
Absences Calendar – No colors, no Absence Type in display

Now we need to get the display information we need from our Absence Type list. We’ll create a workflow using SharePoint Designer to do this.

Looking Up Fields with Workflow

In SharePoint Designer, open your site by clicking File -> Open Site from the menu. Once your site is open, you can create a workflow and attach it to your calendar.

The goal here is to have our workflow update our color columns and our Absence Title so that we can use them in our calculated Display column. Since these columns are not "calculated" by SharePoint, they are not automatically updated whenever the Event is updated.

That means our workflow will need to check to see if the Absence Type has changed. If it has, the workflow will need to recalculate our colors for us.

    • Right click on your site, then click New -> SharePoint Content…

 

Color Coded Calendar with Lookup
New -> SharePoint Content…

    • Give your workflow a name and choose your calendar to attach it. Uncheck manual start and check the other two options: to start (a) when a new item is created and (b) whenever an item is changed.

 

Color Coded Calendar with Lookup
Define your new workflow

    • Click Next
    • Give your step a name, then click Conditions -> Compare Attached Listfield

 

Color Coded Calendar with Lookup
Conditions -> Compare Attached List  field

    • Click on field

 

Color Coded Calendar with Lookup
Setting the conditions on which the Actions will run

    • From the dropdown, choose OldDateType

 

Color Coded Calendar with Lookup

    • Click equals and change it to not equals
    • Click on value and then the fx button

 

Color Coded Calendar with Lookup
Click the "function" (fx) button

    • Leave Source as Current Item, choose Absence Type for Field and click OK

 

Color Coded Calendar with Lookup
Compare OldDateType to the current Absence Type

When the item is first created, OldDateType will not be set, so this condition will work both for Create and Change

    • Click Actions, then Set Field in Current Item

 

Color Coded Calendar with Lookup
Actions -> Set Field in Current Item

    • Click on field and choose Color

 

Color Coded Calendar with Lookup

Color Coded Calendar with Lookup
Set the Color column

    • Click on value, then click fx

 

Color Coded Calendar with Lookup
Click the "function" (fx) button

    • Set Source to Absence Type (or whatever you called your DateType list)
    • Set Field under Lookup Details to Color
    • Set the Field under Find the List Item to Absence Type (or whatever you change the Title field to in your DateType list)

 

Color Coded Calendar with Lookup
Define Workflow Lookup

    • Click the fx button

 

Color Coded Calendar with Lookup
Click the "function" (fx) button

    • Leave Source on Current Item and choose Absence Type for Field

 

Color Coded Calendar with Lookup
Lookup value

The way to read this screen from an SQL understanding is to see the top part (Lookup Details) as the SELECT statement, and the bottom part (Find the List Item) as the WHERE clause.

So we would read this:

Color Coded Calendar with Lookup
Understanding the Workflow Lookup dialog box

…as the SQL statement:

SELECT Color FROM Absence Type
WHERE Absence Type.Absence Type = Payroll Calendar.Absence Type

In other words, look at the Absence Type on my current Event. Now, go look that Absence Type (basically our Title column) in my Absence Type table and tell me what is in the Color column.

    • Click OK

 

When you do, you will see a warning that a unique value is not guaranteed.

Color Coded Calendar with Lookup
Non-unique Warning

This is because, in theory, you could have two Absence Types with the same name in your Absence Type list. In practice, though, you won’t because it just wouldn’t make sense to your end user to have two items in the dropdown list that were exactly the same. Which would they choose?

So, it’s safe to go ahead an click Yes

    • Repeat for BGColor and Absence Title

 

Color Coded Calendar with Lookup
Setting fields

If it seems strange that we are doing the same thing for Absence Title, remember that we cannot use a Lookup column in a calculation formula. By setting the Absence Title equal to the Absence Type, we’re effectively copying the Lookup value to a Single line of text column. We can then use the latter for our formula.

    • Repeat this step one more time for the OldDateType

 

Color Coded Calendar with Lookup
Recording the current Absence Type so the workflow will know if it changes

This is where we are recording the current Absence Type. If this Event is changed in the future, the workflow condition we set in Steps 3-9 will check this field to see if the Absence Type has been changed, so that the colors and Absence Title need to be updated.

    • Click Finish

 

Now your calendar should have all the pieces in place to keep your color-coded calendar functioning properly.

Note: Since the colors and date type text are being updated by a workflow, the changes to your calendar will not be instantaneous. But wait a couple of seconds and refresh your browser and you should see your changes.

 

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

17 Responses to “Color-coded SharePoint Calendar with Lookup DateTypes”
  1. Christophe says:

    Maybe time to update the author’s profile ;-)

  2. There! Thanks, Natasha!

  3. Tim says:

    Jim, Great article. I was hoping you could expand on the actual absence request form. I need a form that does have the all day event option, but not recurrence and workspace. I created a workflow based on the checkbox send email to approving manager and that is working great. I’d just like the form to exclude recurrence and workspace. I did try creating a custom list, but I couldn’t figure out how to add the all day event checkbox & get it to work. Thanks!

  4. Robin says:

    I currently have an InfoPath form that is used to approve employee leave time. Would it possible to use the content type columns I already have to populate a calendar similar to what you’ve done here and how would I go about it??

    Althought I’m the SharePoint admin, forms developer, designer, “guru” here… I’m also still learning, so any assistance would be appreciated.

  5. Tim, I’ve forwarded your question to Iain Munro, who originally asked me the question about using lookup DateTypes. I have not implemented a Leave Request app, but Iain has. Hopefully, he will post his advice here.

  6. Robin, if you are asking if you can use the values from your content type columns, the easy answer is of course. But I am not familiar with InfoPath to know if the answer might be “maybe.” I would be happy to help you figure it out though, if you would like to post a little more detailed information.

    If I can’t help, I know Laura Rogers and/or Lori Gowin certainly can. ;)

  7. “of course” should have been in quotes. ;)

  8. Robin says:

    Thanks for the quick response, Jim!

    The Infopath form pulls data from Active Directory about the current user (name, employee id, email, manager, etc.) The employee fills in the date(s) of leave (a repeating field) and selects the type of leave and enters the hours requested for the type of leave. For certain types of leave (or consecutive hours of leave) attachments are required.

    The form submit button automatically sends an email to the selected manager (the user can choose manager or alternate manager in the case that their manager is sick/on vacation) notifying them of a task to be completed.

    Once the manager approves/rejects the leave form, the form is moved from the submission library to the approved or rejected library.

    All of the leave reports “live” in the Human Resources page of the site (different libraries with custom permissions on these libraries). The manager’s would need to import the data from these forms, however, into calendars that could potentially live anywhere within the site. (The site is setup based on the 7 different divisions of the college, with each department’s page following under it’s respective division’s page).

    Not sure how much detail you all need to help. If we need to take this “off site”… feel free to email me at [email protected].

    TIA!

  9. This sounds like a job for Mark’s Master Calendar solution. Mark?

  10. Robin says:

    where can I find Mark’s Master Calendar solution??

  11. It was an online course he offered. But much of the functionality and concept is contained in several blog posts:

    http://www.endusersharepoint.com/?s=master+calendar

  12. Greg says:

    Hi Jim Bob,
    Sorry to ask this…
    I couldn t figure out what the OldDate Type field is and its role?
    Greg

  13. Don’t be sorry to ask.

    The OldDate Type is used to determine if the Type of Absence is what has changed.

    Other fields may change which cause this workflow to kick off, so we want to make sure that we’re only messing with this when it’s the type of date that changed.

    As soon as we realize that it’s the date type that has changed, we record what the new value is and then move on with our other changes.

    Does that help?

    Blessings,
    Jim Bob

  14. Greg says:

    Hi Jim,
    This definitelly helps.

    Another method would be to use the lookup and a workflow to populate a ‘dummy’ column with the value of the lookup column. I use it in combination with Christophe code to generate hyperlink pointing to subsites.

    I was trying that second method to use the SP ‘approval status’ (another type of field that can’t be used in calculated columns).
    Method was described in http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/1249b5a8-5dd4-4358-b4a7-334a994f7b08

    Running the workflow is updating the ‘dummy’ column properly. However, SP recognized that change and set the Approval Status back to ‘Pending’.

    Would you have any idea how to color code a calendar based on an approval status?
    Whether using the out of the box ‘Approve/ Reject’ function or a 100% workflow solution?

    Best,
    Greg

  15. Iveta says:

    Hi, I am trying to set up a color calendar with a workflow that allows user to submit request for days off, and it needs to be approved by manager , before publishing.
    While using your method, I do not get notification emails for user submitting request, nor confirmation non approval/rejection. I am sure I am missing something. Your article is the closes solution that i have found, but I still can’t make it work. Would you consider making a tutorial for this task?

    I have other color calendar categories on the calendar. If I activate workflow for type Event, all submitted events need to be approved, and i do not want that. Only one category needs to be approved before publishing.
    Thank you for taking your time to read my comment.

Trackbacks

Check out what others are saying about this post...
  1. [...] Bob offered a possible solution with dual workflows on the list.  I thought of another solution using Information Policy Settings and a work flow.  [...]




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!