Question

I have created a simple list in SharePoint 2010 for employees to record their daily activity - each user creates 1 new item each day. When creating this new list, there is automatically a Title column which is required and shows as the first column. However that field is meaningless to this list, so I have currently defaulted it to just say Daily Activity.

I also have 3 other fields:

  1. User currently logged in
  2. Current date
  3. Rich text area for entering Details

I would like to automatically show a combination of the date and the user, for example:

Daily Activity - 10/10/2013 - John Smith

I've done quite a bit with SharePoint, but have never worked with anything like this. How can I make this list automatically combine these fields under the Title field?

Was it helpful?

Solution

  1. If you don't want to write code...

    Use SharePoint Designer to create a workflow that is triggered when the item is created (assuming they can't edit it afterwards in which case you would need to trigger on update as well). Inside of the workflow you can set the value of the Title field using the "Set Field in Current Item" action and a combination of Created, Created By, and "Daily Activity". Just realize that there will be a little delay until the workflow completes and so it is possible that when the list first reloads the Title field might read "(no title)". Here's how to set the value once you've added the workflow:

    a. Click on "Action -> List Actions -> Set Field in Current Item"

    Set Field in Current Item

    b. Click on the "field" link and select your field. In my case it is "Location"

    Field

    c. Click on the "..." button. This will allow to use a combination of other fields to set the value for this field.

    Value

    d. That will bring you to a "String Builder" window. From there you can type in your string "Daily Activity - " and then click on the "Add or Change Lookup" button to add your field "Created" and "Created By". Make sure that when you add "Created" that you select "Short Date" for the "Return field as" dropdown otherwise it will return the date and time. Make sure also that for "Created By" you select "Display Name" for "Return field as" otherwise it will return the name plus the id for that user. In the end your expression will look like this:

    Add or Change Lookup

    Expression

  2. If you want to write code...

    Write an event receiver in c# as Gintas K mentioned and you'll basically be doing the same thing as in #1 above but with code instead. You'll need to hook in to the ItemAdding event. Check out this article.

OTHER TIPS

The simplest method would probably be to create an InfoPath form for your list. For the Title field, set the default value to

concat("Daily Activity - ", today(), " - ", userName())

Uncheck "Refresh value when formula is recalculated", otherwise editing an old item will change its title and potentially overwrite someone else's form. That might be functional enough for your needs, but if you must have formatting like your example check out this or this to get the correctly formatted username, and use translate(today(), "-", "/") for the date.

The simplest no code method is to change the default value for the Title column as a calculated value. This blog shows how to set the value to a year. For your requirements try:

Go to the List Settings, Click the Title column and change the default value.

Paste the following code into the box to give you what you require:

"Daily Activity -" & TEXT(Today,"mm/dd/yyyy") & " - " & Me

Note: The value of Me does not provide the First Last name, but the domain\username.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top