Skip Ribbon Commands
Skip to main content

Laura Rogers @WonderLaura

:

Quick Launch

Laura Rogers @WonderLaura > Posts > Control Formatting of SharePoint Announcements
Hi everyone,
My blog now has a new URL!
You can now find me at http://www.wonderlaura.com
February 07
Control Formatting of SharePoint Announcements

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:

  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.

 

Comments

Stacy

Ahhh thanks just had a client ask for something very similar.  Now I don't have something to start with.
 on 2/8/2012 12:52 AM

Malay

Awesome post. Will definately try it. Thanks for sharing this trick.
 on 2/8/2012 1:26 AM

Andrew

Do I have to make sure the pictures are a certain size and shape. My URL is working, yet I end up seeing a red X where the image should be.
 on 2/8/2012 4:27 AM

Laura

Andrew, look at the code in your announcement that got created in the Announcements list, to see what's wrong.  Double check that you did step 15.
Laura RogersNo presence information on 2/8/2012 9:44 AM

Mark

This is a great example.  One observation:  the default table cell is much larger than the picture used.  I tried setting a default table height in the variable string but it didn't seem to help.  Any ideas? 
 on 2/8/2012 2:11 PM

Laura

Mark,
Hi, you don't have to insert a table, I was just doing that because it's the only way I know of to get the picture to show on the left side of the text.  I'm no HTML guru, but I'd just try creating an HTML page in any old HTML editor and visually get it to what you want and then copy the code to the workflow.
Laura RogersNo presence information on 2/9/2012 10:41 PM

karen

After I have created the template in the Announcements List.
I open it up, place my cursor in the body but I don't see the Markup button and even the spelling button is grayed out.

I have verified that the column settings are defined as per the instructions.
What happened?
 on 7/19/2012 11:45 AM

Karen

I found the issue. I had to change the Form Setting in the List Settings to use SD and not Infopath.
 on 7/19/2012 11:53 AM
​I have disabled any new comments on this, because my blog has moved to a new site.  Please go here: http://www.wonderlaura.com
RSS FeedFacebookYouTube
 

 Our Books for End Users