I was asked how to add a custom column with Hyperlink type on an out-of-box contact list so that the custom hyperlink would display a full name while the link will contain an email address. A calculated column cannot solve this problem because SharePoint converts any anchor tags in any hyperlink in a calculated column from <a href=...>..</a> to <a href=...>..</a> to protect from malicious script attackes. The problem was solved by using a HyperLink column instead of a calculated column and by using a custom workflow which I created using a SharePoint Designer.
The HyperLink field contains the hyperlink information in link, text format. The link, text is converted as <a href='link'>text</a>. So, the trick in SharePoint Designer workflow was to create a variable with String type, and to set the custom variable to store link, text using a 'dynamic string build' action.
Here, as an example, I will create a Contacts list, add a custom column with HyperLink type, and set the value of custom column using a SharePoint Designer.
- From a SharePoint Designer, open the web site which contains the contact list with the custom column.
- Create a new workflow by choosing File -> New -> Workflow from a SharePoint Designer.
- From the "Define your new workflow" window, give a name to the workflow, and select "Contacts" list. Check the following checkboxes:
- Automatically start this workflow when a new item is created
- Automatically start this workflow whenever an item is changed
- Click 'Next'
- Give a name to the Step Name.
- On the bottom of the window, click 'Variables...' button.
- From the Workflow Local Variables window, click "Add..." button.
- On the "Edit Variable" window, set the name to "EmailLink", and select Type to "String".
- Click "OK" to close "Edit Variable" window.
- Click "OK" to close "Workflow Local Varabiels" window.
- Click "Actions" button to see the list of actions.
- Clcik "More Actions..." from the list of actions.
- Select "Build Dynamic String"
- On the String Builder window, create a HyperLink which would be in link, description format. I used the following text to create an email link:
mailto:[%Contacts:E-mail Address%], [%Contacts:Full Name%]
Note: There should be a space(' ') between comma(',') and description. If a space is missing, SharePoint cannot translate the text to a HyperLink.
- Set the variable for the Build Dynamic String action to the custom variable created on Step 6.
- Now we assign the custom variable to the custom HyperLink column. Click "Actions" button and select "Set Field in Current Item" action.
- Set field to the custom column, 'Contact'.
- Set value to Variable: EmailLink (see pic 'Workflow4).
- The workflow has been configured. Click "Finish" button to save the workflow.
Here is a sample screenshot of a Contacts list after I added contact information to the list.
