Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

JS Link not able to access Managed Metadata field values when configured for multiple

$
0
0

This is actually for SharePoint 2016 on-prem, but there does not seem to be a forum for it. 

I have had a js link script running for a while now that would add a "key" icon next to the document icon if certain metadata fields had specified values. The field I was checking was managed metadata field, and everything was working okay while the field was set to only allow single values. Today the customer asked that we allow multiple values in the field and when I made the change I noticed we were no longer getting our "key" icon showing.

I thought it was going to be a simple fix to just update the javascript to loop through the values on the field and check each one to see if it was a match, but for some reason the data is just returned as an empty array, no matter how many items were chosen.

The code I was using previous to the field being changed to allow multiple values is below. Please note that while I know this code will not currently work for multiple values in the THISFIELD field, putting breakpoints in the dev console shows me that the var _THISFIELD is always set to [] as soon as the column is updated to allow multiple values

(function(){
	var statusFieldsCtx = {};
	statusFieldsCtx.Templates = {};
	statusFieldsCtx.Templates.Fields = {"DocIcon":{"View":TypeIconViewTemplate}
	};
	SPClientTemplates.TemplateManager.RegisterTemplateOverrides(statusFieldsCtx);
})();

function TypeIconViewTemplate(ctx, field, listItem, listSchema){
	var _THISFIELD = ctx.CurrentItem.THISFIELD;
	
	var originalDocIcon = ComputedFieldWorker.DocIcon(ctx, field, listItem, listSchema);
	var updatedDocIcon = ComputedFieldWorker.DocIcon(ctx, field, listItem, listSchema) + "<i class='fas fa-key xxx-protected'></i>";
	if (_THISFIELD.Label != undefined && _THISFIELD.Label != "0 - Nothing"){
			return updatedDocIcon;
	}
	else {
		return originalDocIcon;
	}
}

Also note, fields and class names have been changed here to protect the innocent so I hope I did not introduce any typos when doing that



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>