Site icon @WonderLaura

Workflow: Create a Hyperlink

How do you create a link in a SharePoint links list via workflow?  Recently I had an interesting request.  Someone wanted to be able to run a workflow on any document in a library, and automatically have a hyperlink (to that document) added to a links list.  So, I thought I’d share my quick workflow with you, so you’ll know the syntax for creating a link.  This is applicable in SharePoint 2007, 2010, Office 365 sites and SharePoint 2013.

First of all, you could simply create a link using the URL of the current item, but the problem with that is that there would be no description.  I’ll show you:

  1. Create a SharePoint Designer workflow on your document library, which will run when an item is created.
  2. Add an action to the workflow: Create List Item
  3. Click “this list” and choose your links list from the drop-down box.
    SNAGHTML537bfef
  4. Select the URL field, and click the Modify button.
  5. Click the function (fx) button next to To this value.
  6. Choose Workflow Context for the data source and choose Current Item URL as the field.  Click OK, click OK, click OK.
  7. If you go ahead and publish that workflow and run it, you’ll notice that there’s a problem.  Your links in the links list will look like this:
  8. See, the URL is comprised of two different parts, the URL and the description.  We want the description to say the name of the document, and the URL to be a hyperlink to open that document.  Go back to your workflow in SharePoint Designer.
  9. Add the action: Set workflow variable.  (If you’re using SP 2007, use the action “Build Dynamic String” instead, and skip to step 12.)
  10. Click workflow variable and choose Create a new variable.  You can call it DocLink, and make it a string variable.  Click OK.
  11. Click value, and click the three dots (ellipsis) button.
  12. In the string builder, click Add or Change Lookup.  Choose Workflow Context, and Current Item URL, just like in the screenshot at step 6.
  13. Click OK.  Type a comma and a space after it, and click Add or Change Lookup again.  With Current Item as the source, choose Name as the field.  Click OK.
  14. This is what the string looks like.  That’s the trick.  The comma delineates the hyperlink from the URL description.  On this String Builder screen, click OK.
  15. On your already existing action called “Create item in…”, click the name of your links list.  Mine is called “Links”.  Select the URL field, and click Modify again, like in step 4.  Click the function button, just like in step 5.  Change the data source to Workflow Variables and Parameters.  For the field, choose Variable: DocLink.  Return field as String.  Click OK to all dialog boxes.
  16. Publish the workflow again.  Run the workflow on one of your documents again. Notice that the resultant link is formatted correctly:

 


Exit mobile version