TaxonomyField field Term is not populated when the content item is published.

Topics: Writing modules
Nov 14, 2013 at 6:43 PM
Edited Nov 14, 2013 at 6:44 PM
This may or may not be a good idea, but there is some data in fields I would like to add to a content record, so that that information is easily queried. The issue is the Terms.Value property of a TaxonomyField does not appear to be populated when the content type is saved.

The following line works but again Terms.Value is not populated
var series = dynPart.TestPart.TestSeries as TaxonomyField;

Using the debugger I can see that TaxonomyField's driver is responding the publish and has the expected values. I also know that this code executed prior to my part's editor post code.

Is there a way to get this information in the driver's function handling a content item being updated (POST)?

I am doing the same with other Field Types and they all appear to work w/o issue.

Nov 14, 2013 at 9:01 PM
I figured out a way to get the values of the term associated with the content item. This seems to be working fine, not sure if there is an easier path or not?
            var termPart = part.ContentItem.As<TermsPart>();
            var series = string.Empty;
            var seriesUrl = string.Empty;
            if (termPart != null)
                if (termPart.Terms.Count > 0)
                    var termId = termPart.Terms[0].TermRecord.Id;
                    var term = this.taxonomyService.GetTerm(termId);
                    series = term.Name;
                    seriesUrl = string.Concat(this.context.WorkContext.CurrentSite.BaseUrl, "/", term.Slug);