1,650 articles and 12,427 comments as of Sunday, August 1st, 2010

Thursday, July 29, 2010

SharePoint: Extending the DVWP – Part 23: Creating Title Based on Other Fields with a Workflow

Author: Jim Bob Howard

When working with cascading dropdowns and the Relationship lists that accompany them, the important part of the Relationship list is that the site columns we’re relating are set. The Title of the list time doesn’t matter to the cascading process.

However, from a human maintenance standpoint, that Title can make things a whole lot easier. Last time, we automated its creation using jQuery. I know not everyone enjoys jQuery as much as I do. But, I have good news for you…

You can do almost the same thing with a workflow.

Creating a Title Within a Workflow

Of course, you’ll need SharePoint Designer to create the workflow. So, launch that and open your site:


Site opened in SharePoint Designer

  1. Click the arrow next to the new document icon and choose Workflow:

  2. Site opened in SharePoint Designer

    You may see this message:


    …if so, just wait and then you’ll see the Workflow wizard


  3. Give it a name

  4. Choose the list

  5. Uncheck "manual start" and check "on create start"

  6. Click Next

  7. Then click Actions and choose Build Dynamic String

  8. Click on dynamic string

  9. Click Add Lookup

  10. Leave Source as Current Item, and set Field to the first field you want to be part of the Title. In mine, I want Date of Incident:

  11. Click OK
  12. Type a space, a dash, and another space (or whatever naming convention you want):


  13. Click Add Lookup again
  14. This time, choose the second field you want to use (I’ll use Type of Incident):


  15. Click OK twice
  16. Click on Variable: variable 1

  17. Then click on Create a new variable…


  18. Name it

  19. Click Actions and choose Update List Item

  20. Click this list

  21. Click Add and choose Title under Set this field

  22. Click the fx button
  23. Change the Source to Workflow Data and Field to txtTitle


  24. Click OK three times
  25. Click Finish

Now you have a "dynamic" Title.

Caveats

The downsides to using a workflow are irritating, but not necessarily show-stoppers.

  1. The most obvious downside is that the Title is not set immediately. The workflow takes a little time to process. In the meantime, it will be blank and could confuse users, mess up sorting on that field, and generally look less than optimal.
  2. Any field used in the Title must either be required or you must check for it in the workflow and give a default if not found. If you’ve worked with workflows for any time, you’ll know that using conditionals and branching is non-trivial.
  3. If the workflow ends with an error, your Title may never be set.
  4. If the fields used to set the Title change, it’ll be out of sync. To get it back in sync, you’ll have to write a WF that runs on create AND change, but you’ll have to keep track of the fields and check to see IF they changed before changing the Title.
  5. If you’re keeping track of versions, you’ll have a new version every time the Title gets set or reset.
  6. Showstopper: If the creator doesn’t have Edit permissions (e.g. Contribute w/o Edit), this WF will fail because the workflow runs under their ID so Update List Item will be denied access.

Next time: We’ll look at creating list items with SPServices next.

Author: Jim Bob Howard

Jim Bob Howard is a web designer / webmaster in the healthcare industry. He has been working with SharePoint since March 2009 and enjoys sharing what he has learned. He is a moderator and frequent contributor to Stump the Panel, and answers SharePoint questions on Twitter (@jbhoward) and via email ([email protected]).

View all entries in this series: Extending the DVWP»
Entries in this series:
  1. SharePoint: Extending the DVWP - Part 1: Layout Enhancement - Rearranging Columns - Default and Edit Templates
  2. SharePoint: Extending the DVWP - Part 2: Layout Enhancement - Rearranging Columns - Insert Template
  3. SharePoint: Extending the DVWP – Part 3: Getting it All on One Line - DVWP Function Action Links
  4. SharePoint: Extending the DVWP – Part 4: Turning DVWP Action Links into Buttons
  5. SharePoint: Extending the DVWP – Part 5: Doing Stuff Before Save on Submit - PreSaveAction()
  6. SharePoint: Extending the DVWP – Part 6: Examining the Form Action Links
  7. SharePoint: Extending the DVWP – Part 7: Creating a Form Action Workflow
  8. SharePoint: Extending the DVWP – Part 8: Creating a Form Action Workflow - The After Math
  9. SharePoint: Extending the DVWP – Part 9: Oops! Failed Setting Processor Stylesheet
  10. SharePoint: Extending the DVWP – Part 10: Passing Workflow Variables to a Form Action Workflow
  11. SharePoint: Extending the DVWP – Part 11: Getting More Form Fields to the Workflow
  12. SharePoint: Extending the DVWP – Part 12: Adding More Form Fields from the Data
  13. SharePoint: Extending the DVWP – Part 13: Putting PreSaveAction() to Work – Creating Variables
  14. SharePoint: Extending the DVWP – Part 14: Putting PreSaveAction() to Work with jQuery
  15. SharePoint: Extending the DVWP – Part 15: User-Managed Dropdowns with Site Columns
  16. SharePoint: Extending the DVWP – Part 16: User-Managed Dropdowns - Loading Data
  17. SharePoint: Extending the DVWP – Part 17: User-Managed Dropdowns – Creating a Relationship list
  18. SharePoint: Extending the DVWP – Part 18: User-Managed Dropdowns – Loading the Relationship list – Part 1
  19. SharePoint: Extending the DVWP – Part 19: User-Managed Dropdowns – Loading the Relationship list – Part 2
  20. SharePoint: Extending the DVWP – Part 20: Cascading Dropdowns - Applying the jQuery
  21. SharePoint: Extending the DVWP – Part 21: Cascading Dropdowns - Three-tier Cascade
  22. SharePoint: Extending the DVWP – Part 22: Creating Title Based on Other Fields with jQuery
  23. SharePoint: Extending the DVWP – Part 23: Creating Title Based on Other Fields with a Workflow
 

Please Join the Discussion

2 Responses to “SharePoint: Extending the DVWP – Part 23: Creating Title Based on Other Fields with a Workflow”
  1. Greg says:

    Jim,
    What drawbacks to you see to the jQuery option?
    Seems that if you are confortable with jQuery and already using it on the same page, the workflow option is less reliable.
    Correct?
    Greg

    • Dear Greg,

      Correct. I prefer not to use the workflow option for this, but I present it as a contrast for how great the jQuery option is. ;) I think jQuery FAR excels the workflow in this case.

      But, if you aren’t already using jQuery, but ARE already using a workflow (and the other caveats don’t apply or can be mitigated), then you might as well throw the Title-naming into the workflow.

      Blessings,
      Jim Bob


Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!