Tuesday, March 27, 2012

Control Formatting of SharePoint Announcements

Here are the steps:

  1. Create an "Announcements" list, if there isn't already one on your site.
  2. Create a list called "Create Announcements", using the list template "custom list".
  3. Create the following columns in the Create Announcements list:
    Green Header - Single line of text
    Brown Header - Single line of text
    Body - Multiple lines of text - Enhanced rich text
    Photo URL - Hyperlink
    Expiration - Date/Time
    Then, I renamed "Title" to "Black Title"
  4. In the Announcements list, a template must be created. Create a new announcement. Make up a title, and then put the cursor in the body of the announcement. Since I want to show the speaker's photo to the left of the session description, I create a table. On the Insert tab, insert a table that's got one row and two columns.
  5. In the left cell of the table, type "Picture", as a placeholder. In the right cell, type the following:

  6. Now it's time to apply the colors. Select the text, and apply your desired colors to each line, as so:

  7. Click Save.
  8. Open that same announcement back up, click to edit it, and put the cursor in the Body field. Open the HTML source code, like this:

  9. Copy the HTML code to the clipboard. Open SharePoint Designer.
  10. Create a new workflow based on the Create Announcements list. Name it "New Announcement".
  11. Add an action to set a workflow variable. (In SharePoint 2007, the action is called Store Dynamic String) Call the variable BodyTextVar, and it is a string variable.
  12. Click the blue word Value. Click the little ellipsis next to it (the button with 3 dots). Paste the contents of the clipboard, which is the HTML source code. Mine looks like this
    <div class="ExternalClassF2152D91E5604C86AA56CB2DF7047264"><table width="100%" class="ms-rteTable-default" border="0" cellspacing="0"><tbody><tr><td>Picture</td><td><p style="color: #000; font-size: 18pt"><strong>Black Title</strong></p><p style="color: green; font-size: 12pt">Green Header</p><p style="color: #8f6c2e; font-size: 10pt"><strong>Brown Header</strong></p><p>Body</p></td></tr></tbody></table></div>
  13. In the spot of the code where you see the word "Picture", that needs to be changed to HTML code for a picture. The Photo URL field will be used. Basically, each placeholder in the code will be replaced with the name of the actual field from the list, like this:

  14. Note that when you insert the Body field, be sure and change Return field as: Plain Text.

  15. When you insert the Photo URL field, be sure to select Return field as: URL
  16. I used the <Add or Change Lookup> button in the code, to insert where the fields need to go. For example, I replaced Green Header with the actual field called Green Header. Click OK.
  17. In the workflow, add the action Create List Item.
  18. Click the blue words This List, and pick Announcements.
  19. Set the Title field to the current list's Black Title, and click the Add button. Add the body field, like this, and click OK twice.

  20. One more field. Click the Add button. Choose "Expires" and match it to the current list's "Expiration". The Create new list item action will then look like this. Click OK.
  21. Publish the workflow. Note that since we didn't change the workflow initiation (Start) settings, it is only set up to be triggered manually, which is fine for testing.
  22. Before you create an item in the Create Announcements list, be sure to get the URL of a photo that's in a library in SharePoint, to paste into the Photo URL field. Create a new item in the Create Announcements list, and fill in all the fields. Run the workflow.
  23. You'll notice that your new announcement gets created. Lovely! Any tweaking that needs to be done regarding formatting and alignment needs to be done in the HTML code that's in the first action "set variable" in the workflow.
  24. Another enhancement: You may want users to be able to create items in Create Announcements but not create or edit items in the actual announcements list. This can be done. In the workflow, insert an Impersonation Step, and put those 2 steps inside of it. That way, you can take away the users permissions to contribute to the announcements list, and the workflow will still be able to create items in it, because it runs with the credentials of you, the person who published the workflow.
  25. The web part view: In the Announcements list, create a new view. Make it a Standard view, and call it Web Part. Only check the box next to the Body column. Set the filter so that Expires is greater than or equal to [Today]. Uncheck the box next to Tabular View.
  26. On the home page of your site. Go to the web part toolpane of the Announcements web part. Change the view to this new Web Part view that you just created. Click OK. What is this for? Now, your announcements will be fully displayed on the home page without being cut off, and since we inserted the title field into the body of the announcement, only the body field needs to be shown.

display a “More” link on your announcements web part

Here is how to display a “More” link on your announcements web part, so that users will have an obvious link to click on, to read more of each announcement.

  1. Create a new column in your announcements list called “More”, with a field type of “Hyperlink or Picture”
  2. In SharePoint Designer, create a new workflow - Open SharePoint Designer, and click <File> and <Open Site>
  3. Put in the URL of the site where you’d like to create the workflow, and open it.
  4. Click <File>, then <New>, then <Workflow>
  5. Pick your Announcements list from the drop-down list. Only check the box “Automatically start this workflow when a new item is created”.



  6. Note: If there is already a workflow running when a new item is created in this list, such as the one created in the first section of this article, I recommend adding this as a new step in the same “Create Announcement” workflow, as opposed to having two different workflows running when each item is created in the list.
  7. This workflow will have no condition.
    Action: Build Dynamic String
    Click on dynamic string, which will take you to the String Builder dialogue box. Type a backslash, then click the <Add Lookup> button.
    More Link

    Pick the Path field, and click OK, then type the rest of the string as so:

    More Link

    (The reason for the comma and “Click Here” is so that users aren’t presented with a big long URL to click, but some nice, short text)

    Give the variable a name such as AnnouncementURL
  8. Next Action: Set Field in Current Item -
    Set the More field to … click the function button.
    More Link

    In the Source drop-down box, choose “Workflow Data”, and for the field, choose the variable that you called “AnnouncementURL” in step 6 above.
    More Link
  9. Now, in the announcements web part on your site, edit the web part properties, edit the current view, and add the new “More” field to the view.
  10. You can even hide this new field, so it doesn’t display on your announcement forms. In the announcements list settings, go to Advanced settings. Change the setting “Allow management of content types” to Yes.
  11. Now, there’s a new section in your list’s settings called Content Types that contains one content type called “Announcement”.
  12. Click on the Announcement content type, click on the More field, and change it to Hidden. This will still allow the column to be added to any view, but the field will be hidden when opening or editing the announcement itself.

Create a alert based Annoucements

Here’s how to use a single announcements list, categorize the announcements by department, and allow alerts to be created per category. This list can also be set up to display only the announcements of the logged in user’s specific department.

  • In your announcements list, create a new column called “Department”, as a text box, choice list, or even a lookup to a separate list of departments.
  • In the list, create a new, filtered view for each different department, like this:
    Click the View drop-down box at the top right of the announcements list, and choose “Create View”, choose Standard View.
    In the Filter section, choose to filter by Department is equal to department name.
    Do a new view for each department.
  • Now that the filtered views exist, alerts can be set up based on them.

Try it out. On the announcements list, click <Actions> and choose <Alert me>. You’ll notice that in the “Send Alerts for These Changes” section, there’s a new option that lets you choose to be alerted on items that exist in a particular view.

Alerts

In this case, it’s a particular department’s announcements. Also, as an administrator, since you have the ability to set up alerts for other people, you can create a new alert based on new items created in the view for each department, and have that alert sent to members of a departmental group in Active Directory.

Publish Date functionality for Announcements

The ideas for this set of articles comes from user questions on Stump the Panel regarding customizations and optimizations to announcements lists on SharePoint sites. I will cover the following customizations:

  • Create a Publish Date feature for announcements
  • Create alerts based on announcement categories
  • Modify the default “Current View” of the announcements Web Parts
  • Create a “More” link to view the details of each announcement

Create a Publish Date functionality for Announcements


Here’s how to create a publish date for each of your announcements, where the announcement will automatically be “published” when the date arrives.

  1. Turn on content approval on your announcements list like this:
    In the list’s settings, go to Versioning settings.
    Change “Require content approval for submitted items?” to Yes
    Date Functionality
  2. Create a new Date and Time column in your announcements list called “Publish Date”, and make it a required column. You can even make it default to today’s date if you’d like.
  3. In SharePoint Designer, create a workflow like this: Open SharePoint Designer, and click <File> and <Open Site>. Paste in the URL of the site where you’d like to create the workflow, and open it. Click <File>, then <New…>, then <Workflow…>
    Date Functionality
  4. Name this workflow “Create Announcement”
  5. Pick your Announcements list from the drop-down list. Only check the box “Automatically start this workflow when a new item is created”.
  6. Add the first condition to “Compare Announcements field”. If the field Publish Date is less than or equal to (then, click on value, and choose the little parameter builder button)
    Date Functionality
    Then, choose Current Date, and click OK.
  7. In the Actions section, choose Set Content Approval Status. Set content approval status to “Approved”, and add comments such as “item automatically approved on publish date”
  8. But, if the announcement is supposed to be published on a future date, we need the workflow to wait. Click to Add ‘Else If’ Conditional Branch. In the new branch’s Action section, choose Pause Until Date. Click on this time, and click the function button to display the data binding menu
    Date Functionality

    With the Source as Current Item, choose Publish Date as the field. Click OK.
    Date Functionality
  9. The second action will be the same as the action on the previous branch.
    Set content approval status to “Approved”, and add comments such as “item automatically approved on publish date”

Here’s what your workflow screen will look like:

Date Functionality

We used “is less than or equal to Today” as the condition (instead of is equal to today) because it’s possible that a user could enter in a past date as the publish date. A condition is not needed in the second branch because it knows that if the condition in the first branch is not met, then otherwise do this.