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.
Great, solution but i’m having issues. Are there any other steps I’m missing this makes sense but is not functioning? Do I need to reference a javascript libarary? Thanks!!!
@adam:
Hard to say since you haven’t described what what you’ve done or what the issues are!
M.
Great solution Phil. To elaborate on Philips solution, I added a replace statement to remove the trailing semi-colon when more than 1 item is added. This is accomplished by getting the count of the number of semi-colons from the main string. Look for the replace statements near the bottom. Cheers!
$(document).ready(function() {
$(‘nobr:contains(“column2”)’).closest(‘tr’).hide();
});
function PreSaveAction() {
var str = $(“input[id=’ctl00_m_g_d0f8683a_b3b6_4e79_875b_a18b15ca5b66_ctl00_ctl05_ctl01_ctl00_ctl00_ctl04_ctl00_ctl01′]”).val();
var result = str.split(“;”);
var finalresult = “”;
var count = (str.match(/;/g) || []).length;
//Clean metadatafield text. Remove guids
$.each( result, function( i, val ) {
var resultB = val.split(“|”);
finalresult = finalresult + resultB[0] + “; “;
});
//Save output in Column2Name
if (count > 0){
$(“input[id=’ctl00_m_g_d0f8683a_b3b6_4e79_875b_a18b15ca5b66_ctl00_ctl05_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00_TextField’]”).val(finalresult.slice(0,-1).replace(/;+$/,”));
return true;
}
else{
$(“input[id=’ctl00_m_g_d0f8683a_b3b6_4e79_875b_a18b15ca5b66_ctl00_ctl05_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00_TextField’]”).val(finalresult.slice(0,-1).replace(“;”,””));
return true;
}
};
I’m in 2019 On Prom and here’s what I did:
Create a multiline text field in your source list, call it “KeywordsCalc”
In your PreSaveAction copy the data from the source metadata field to the multiline text field we created in step 1.
var keywords = $(‘[id^=”Keywords_$containereditableRegion”]’).text();
$(‘textarea[id^=”KeywordsCalc”]’).val(keywords);
Create a multiline text field in your destination list to receive the data.
In your workflow pass the data from the Multiline field in the source list to the multiline field in your destination list.
This copies the data over without all the extra pipes and long numbers, ie: Keyword1;Keyword2;Keyword3; etc
Of course, in the destination list you lose the connection to the term store but in my case I didn’t need it. But the keywords display exactly as desired.
HTH