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.
    SNAGHTML53af699
  6. Choose Workflow Context for the data source and choose Current Item URL as the field.  Click OK, click OK, click OK.
    SNAGHTML53be1f0
  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:
    image
  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.
    SNAGHTML5536d1f
  11. Click value, and click the three dots (ellipsis) button.
    image
  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.
    SNAGHTML558fd5d
  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.
    image
  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.
    image
  16. Publish the workflow again.  Run the workflow on one of your documents again. Notice that the resultant link is formatted correctly:
    image

 

Advertisements

22 comments

  • This is Excelente! i saw this post too, and helped me a lot:
    http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomizationlegacy/thread/ea1677b0-02a2-41fb-a1d6-ac5db4f6eee3/

    Thanks so much, i was thinking to begin a development…

    Like

  • This is great Laura, the URL field is tricky updating via workflow – I haven’t thought of being able to do it. I did something similar pointing to an InfoPath form – unfortunately there’s not a Workflow Variable for the edit form of an item! I had to use the [%Workflow Context: Current Site URL %]/Lists/ListName/Editform.aspx?Id=[%Current Item:ID%].

    Like

  • This seems to work will when you are trying to add a link to a links list. I have tried to go through a similar process to create a list item in a document library with the content type id switched to “Link to a Document”. I have tried all diferent combinations of values for the “Path and Name” and “URL” fields with no luck. Is it possible to do this? If so, can you provide any information on which fields need to be filled out with what data?

    Like

  • Hi Ben,
    I’m not sure, I’ve never tried to do that.

    Like

  • I did a lot of searching and no one seemed to have a way to create a link using a workflow. Thus, what I ended up doing was: 1) manually created a “Link to a Document” in a folder, 2) created a workflow to first create a copy to the “Link to a Document” and second update the properties of the copy. This seems to be working well thus far.

    Like

  • Thanks Ben, that’s a great tip!
    I also got stuck with an error “Unauthorized to http://rtm.contoso.com/it/projects/_vti_bin/client.svc/web/GetFolderByServerRelativeUrl('/it/projects/Documents‘)/Files/Add(url=…
    (at least in 2013 WF)

    Like

  • This is what I was looking for.. I have been struggling with this issue for so long.

    Thanks a lot 🙂

    Like

  • Mary McLaughlin

    Hi Laura,
    Thanks for this! I’ve been trying to figure out a way to replace a Document Set Library “Name” column with a link to the Document Set welcome page. (In our case, we wanted to let the user know to enter the Project Name as the Document Set Name, and the Document Name is the name of the document. Since renaming the column to Project Name also renamed the Document content type “Name” column it caused confusion when the user created a new Doc Set Instance). Nothing worked except this, I created a hyperlink column to use as the link to item.
    However, if the Project name contains an apostrophe, the link description adds a 's to the title (e.g. Children's Toys). Is there any way to get around this? (Or for that matter, a better way to rename the doc set name column so it doesn’t rename the document name column!)
    Thanks so much, your site has been a huge help to me more than a few times.
    Mary (@merimac21)

    Like

  • Mary McLaughlin

    Hi Laura,
    Thanks for this! I’ve been trying to figure out a way to replace a Document Set Library “Name” column with a link to the Document Set welcome page. (In our case, we wanted to let the user know to enter the Project Name as the Document Set Name, and the Document Name is the name of the document. Since renaming the column to Project Name also renamed the Document content type “Name” column it caused confusion when the user created a new Doc Set Instance). Nothing worked except this, I created a hyperlink column to use as the link to item.
    However, if the Project name contains an apostrophe, the link description adds a 's to the title (e.g. Children's Toys). Is there any way to get around this? (Or for that matter, a better way to rename the doc set name column so it doesn’t rename the document name column!)
    Thanks so much, your site has been a huge help to me more than a few times.
    Mary (@merimac21)

    Like

  • Hi Laura,

    Your website and Youtube videos are wonderful! Thank you so much for all the great explanations.

    I have a list of all of my company’s active clients. Each item has a link in a column named “Hub,” and the link goes to a page with a bunch of web parts and a query string URL filter of the company’s name. The query string is populated by a lookup in the string builder. The problem is that if the company name has a comma in it, the url stops at that comma and takes the rest to be the description. So when I’d like the link to be
    yaddayadda.aspx?Client=Acme, Inc.
    and the text to be “Hub,” I get a link of
    yaddayadda.aspx?Client=Acme
    and text ” Inc., Hub”.

    I’ve been banging my head against the wall all day trying to work around this in Sharepoint Designer. Any help would be greatly appreciated!

    Thanks again for basically teaching me everything I know about Sharepoint!

    Thomas (@TomStripes)

    Like

  • Thomas,
    I haven’t tried this, but could you create another w/f variable to hold only your URL (which may have a comma), then use that variable as the url portion in the string builder. That way the variable hides the embedded comma, so the comma you need to separate URL from description is the only comma seen.

    Like

  • When I tried out this workflow, it creates an entry in the links list, but the entry has no name at all, that field is just blank! Any idea why?

    Like

  • Charlene Stewart

    Is there a way to link the workflow status url onto an infopath form. So at any moment the client or approver could see what step the item is on?

    Like

    • I wouldn’t typically attempt to do that via a URL, but I’d have some field that has just text of what the status field is (even if it’s a field they can’t edit) and then just display that on the form.

      Like

    • Charlene Stewart

      Thank you so much for your response! I did not expect you to get back to me. I will try to pull the other data in but have not had much success. Thank you again

      Like

  • This is useful information Laura and one day I hope to use it. One question I have though is I want to add a link to the editform of my list item. My list has spaces in the name and it is breaking the link in the email. Is there a way to urlencode these strings?

    Like

    • is it a sharepoint designer workflow email? Construct the hyperlink by creating a workflow variable where you do a hyperlink like a href=”urltoyoursite/lists/list%20name/editform.aspx?id=[id of current item]” >click here /a
      When I put an actual, functioning hyperlink in this post, it tried to make it a link in this comment, so I removed some of the tags.

      Like

  • Pingback: Extracting the URL from Document Library’s Link type – It's all Greek

  • Pingback: Extracting the URL from Document Library’s Link type – do.IT

  • Pingback: Custom Hyperlink Icon Column | @WonderLaura

Leave a reply or question

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s