We like to give people the freedom to add content to SharePoint as they wish in most cases, and we like them to be able to add announcements on their site whenever they need to. Do you ever cringe when you look at a SharePoint site, because of some crazy font or ugly colors that were used in the announcements that are prominently displayed on the home page? In this post, I'll show you how to tightly control the formatting of the way announcements look on your site.
This solution will work in either SharePoint 2007 or 2010, and will work on any version such as Foundation or Enterprise. This is also a good fit for SharePoint Online with Office 365.
A quick little bit of background… I maintain the site for the Birmingham, Alabama SharePoint User Group, and every month I post an announcement about the next upcoming meeting. The announcement is formatted the same way each time, with the speaker's photo on the side and a certain font used for the name of their presentation, and a certain font used for the date, and a different one for the description. Each month when I was adding a new announcement, I decided it was taking too long to do all this formatting, even though it was the same every time, which is what prompted me to create a workflow. So, although my motivation was just efficiency, your motivation may be uniformity among announcements.
In my SPUG announcements list, I have specific field names such as the speaker's name, the sponsor name, the speaker's job title, etc. For simplicity's sake, I'm going to keep the field names pretty generic for this post.
Here are the steps:
- Create an "Announcements" list, if there isn't already one on your site.
- Create a list called "Create Announcements", using the list template "custom list".
- 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"
- 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.
- In the left cell of the table, type "Picture", as a placeholder. In the right cell, type the following:
- Now it's time to apply the colors. Select the text, and apply your desired colors to each line, as so:
- Click Save.
- 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:
- Copy the HTML code to the clipboard. Open SharePoint Designer.
- Create a new workflow based on the Create Announcements list. Name it "New Announcement".
- 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.
- 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>
- 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:
- Note that when you insert the Body field, be sure and change Return field as: Plain Text.
- When you insert the Photo URL field, be sure to select Return field as: URL
- 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.
- In the workflow, add the action Create List Item.
- Click the blue words This List, and pick Announcements.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.