Displaying Managed Metadata Column Values in an Email Sent from a SharePoint Designer Workflow
Managed Metadata columns are so cool and so nasty at the same time. If you want to display the value of a Managed Metadata column in a SharePoint Designer workflow, you get a horrible representation of it like ‘TermText|ba7e2a4f-6602-47a8-aa81-bca54756a356’.
The only solution I know for this is the one in the comment from Kristina P on Michal Pisarek’s (@MichalPisarek) blog post Managed Metadata Column Limitations (a post which I find myself referring to far too regularly).
Here’s the meat of it:
- Start with your managed metadata column (Column1Name)
- Create a 2nd column (Column2Name) in the list of type string
- Create a workflow that fires on create and/or on modify (depending on your needs) that copies the value from Column1Name into Column2Name.
- Create a 3rd calculated column (Column3Name) on the list. The formula for that column should be =LEFT([Column2Name],FIND(“|”,[Column2Name])-1) The calculation finds the pipe character and trims the value to a clean text value.
- Any emails where you need to display the value of Column1Name should use the value of Column3Name instead to send the plain text
++++++++++++++++
Separately, I am having issues with the workflow (which I really don’t think I should even have to use!). I’ve posted a question about it over on SharePoint StackExchange: SharePoint Designer Workflow Not Always Firing.
The workflow generally does exactly what it should. The issue we’re running into is that occasionally (and we haven’t figured out any pattern to it) the workflow simply doesn’t fire when a new item is created. It’s not that it fails, it never fires. There’s nothing in the workflow history for the item. I also don’t see anything like an error in the timer job history for the workflow job. It just seems like the workflow simply doesn’t fire.
If you have any idea what would cause occasional non-firing of such a simple workflow, I’d really appreciate your thoughts over on the SharePoint Designer Workflow Not Always Firing post.
I haven’t tried this out but managed meta data columns are nothing more than a regular lookup fields. It should be possible to lookup the correct value from the taxonomyhiddenlist and use then the values in SharePoint. Never tried this out but it is my first idea I came up. There you might not have to add columns.
Hi Stfbauer,
Could you please tell me how to get value from taxonomyhiddenlist?this list is not found in SPD workflow..
Thanks
Sappai:
FWIW, I wasn’t able to find it, either. Perhaps Stefan can shed some light.
M.
I have a metadata field which allows multiple selection..above described works for single selection..Could you please tell me how to get value if its multiple selection?
Sappai:
I don’t have a good idea on how to render multi-valued managed metadata columns. This approach is a bit of a kludge as it is.
M.
There is a way to do it in SharePoint 2013: http://www.fiechter.eu/blog/Lists/Posts/Post.aspx?ID=37&mobile=0
Adrian:
Nice trick. It’s still horribly messy given what we’re trying to accompish. Thanks for sharing.
M.
Adrian this link does not work.
Try this:
1) **Find substring in string** in which:
– substring is just the pipe | character
– string is your metadatafield_0 field
– output: index1
2) **Extract substring from string with length** in which:
– substring is your metadata_0 field from the current item
– starting location is 0
– end is the output of the first step (index1)
– output: substring1
Now log substring1. In my case this results exactly in all characters in front of the pipe character:)
Jaap:
I swear I tried to go this sort of route and couldn’t get there. I don’t see **Find substring in string** in the installations I can get to. The only “Find” action I see is minutes between dates.
If it works for you, I believe you, and boy does it make me question my approach!
M.
This worked for me too. Much better than adding 2 extra columns….especially when I had 4 of these fields to include in my email!
Jaap, this works very well in SPD 2013. Thank you so much!! :-)
Hey there. Looks like your site is getting a lot of hits about managed metadata and workflows so I thought I would share a solution.
I also had an issue not seeing the “Find substring in string” action in SPD 2013. The issue I found out with mine was that I was working with a workflow created with SP 2010 and not 2013.
Recreate the workflow in 2013 and you’ll have all the string manipulation actions available.
Sonny:
That’s a great solution, should you be using SharePoint 2013. Many, many people are still on SharePoint 2010 and probably will be for years. It’s a shame there isn’t an easier way to do this.
M.
Marc,
I am also facing issue where SharePoint workflow simply doesn’t fire when a new item is created or item edited. Times I have to re-start workflow manually, or edit item again.
Is there any fix ?
Thanks,
Parth:
There are many reasons why a workflow might not fire or may fail. IMO, the workflow engine isn’t highly reliable in the first place. I see too many instances simply not run. You also may have code in place which is interfering with the workflow or it may have an error in it.
M.
Hi All,
Just wanted to share a slightly different way I have come up with to extract those horrible managed metadata fields into an email or even link into from other sharepoint lists.
1. Start with your managed metadata column (Column1Name)
2. Create a 2nd column (Column2Name) in the list of type string
3. In Sharepoint Designer, edit the NewForm.aspx
4. Insert this Jquery Script Below: (it will help if you know a bit of JS)..
//Initiate this function when user clicks save
function PreSaveAction() {
//Extract Metadata fields from Column1Name
var str = $(“input[id=’Column1NameControlID’]”).val();
var result = str.split(“;”);
var finalresult = “”;
//Clean metadatafield text. Remove guids
$.each( result, function( i, val ) {
var resultB = val.split(“|”);
finalresult = finalresult + resultB[0] + “,”;
});
//Save output in Column2Name
$(“input[id=’Column2NameControlID’]”).val(finalresult.slice(0,-1));
return true;
};
$(document).ready(function()
{
//Hide Column2Name field from form to prevent people editing it
$(“nobr:contains(‘Column2Name’)”).parent(‘h3’).parent(‘td’).parent(‘tr’).hide();
});
Note:
– You need to look at form source to extract the Column1NameControlID and Column2NameControlID
it looks something likes this:
ctl00_m_g_d9ee4f4c_54f1_4717_a3de_367865144c80_ff311_ctl00_ctl00_TextField
– This will work with multiple metadata fields
– You can now reference Column2Name in all emails/workflows
– You can now link in Column2Name from other lists
I hope this gives people ideas on other ways to work round this issue.
Wanted to say thank you, thank you!! You keep things simple and straight to the point which I like about your article on this topic. I needed to add in some managed metadata from the Term Store for my project at work and this was exactly what I needed. I did some messing around with it and unfortunately the issue of it firing does exist. This next part is based entirely on my own speculation as I did originally get the same issue of the workflow not starting. It would simply not update the field when putting it into the email so I understand that is a big problem at times. However, I realized that the calculated column will take some time to complete, so I added a pause for 1 minute and it seems to fix the issue. Try it out if you would like and let me know if that works for you.
How do you do if your column has multiple managed metadata values ?
Alexandre:
That would be a lot uglier. Because the string manipulation actions in workflows are rudimentary at best, you may not be able to do much.
M.