Thursday, February 27, 2014

Dynamically constructing the List Item Url in a SharePoint Designer 2013 Workflow

If you have worked with SharePoint Designer workflows in the past, you may know that it is not very easy to construct dynamic Urls to use in sending e-mail messages from a SharePoint Designer workflow.

In fact, Microsoft articles such as this one actually recommend using a hard-coded Url in your workflow in order to achieve this functionality:

Well, as most developers, I despise hard coding anything into my applications because it makes their functionality very prone to failure.

Fortunately, with the new Actions available in SharePoint Designer 2013, I no longer have to hard code Urls thanks to a new workaround provided by some of these new Actions.

In order to make this work, you will be leveraging the default value of "Encoded Absolute Url" and then doing some workflow variable assignment and string manipulation:

  1. Set a new Workflow Variable to the current ID of the List Item
  2. Create another Workflow Variable to construct the ending Url that you desire to View or Edit the item (DispForm.aspx or EditForm.aspx) and append the List Item ID to it:   Ex: DispForm.aspx?ID=[%Variable:ListItemID%]
  3. Then perform a string replacement of the ID which appears by default in the "Encoded Absolute Url" field with the appropriate ending portion of the Url such as this: Ex: Replace [%Variable:ListItemID%]_.000 with Variable:DisplayListIDUrl in Current List:Encoded Absolute Url (Output to Variable:ReplacementUrl)
  4. Use the resultant ReplacementUrl variable to output the text in the body of the e-mail message.
  5. That is it!!  You have now created a dynamically generated Url to the appropriate List Item without hard-coding the value into your workflow!! Yippee!! Woo hoo!!

No comments:

Post a Comment