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:
    ​Picture

    ​Black Title

    Green Header

    Brown Header

    Body

    • 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.
      020812_0458_ControlForm5
    • When you insert the Photo URL field, be sure to select Return field as: URL
      020812_0458_ControlForm6
    • 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.
      020812_0458_ControlForm8
    • 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.

14 comments

  • Ahhh thanks just had a client ask for something very similar. Now I don’t have something to start with.

  • Awesome post. Will definately try it. Thanks for sharing this trick.

  • 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.

  • 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.

  • 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?

  • 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.

  • 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?

  • I found the issue. I had to change the Form Setting in the List Settings to use SD and not Infopath.

  • Karen,
    Great, you’re right, this won’t work with InfoPath in place.

  • Hi Laura, I am having difficulty showing the picture in the announcement as it keeps displaying the url. I was not sure on how to set the picture placeholder which could be my problem.

    Many thanks

  • Ben,
    I had a similiar issue. My fix was to modify the URL to only include “/CurrentSite/SiteLibraryName/PicName”.

    I removed the from the http:// all the way down to the parent site of my current site where the picture was located.
    Thanks

  • Great idea, Bob, making it relative instead of absolute.

  • Hi Laura,

    Is there anyway I could use this workflow you have just described to make attachments appear within the announcement webpart? IE: If I attach 2 items when creating the announcement, how can I make those attachments appear on the announcement itself on the page?

    Thanks!
    – Dave

Leave a Reply