Apply custom classification to Dynamic Content Items

Posted by Community Admin on 04-Aug-2018 17:29

Apply custom classification to Dynamic Content Items

All Replies

Posted by Community Admin on 16-Oct-2014 00:00

I have a Dynamic Content type that has two fields of type Classification, that correspond to custom classifications I've created.  Using the API, how does one set the values for these classification fields?

 I've tried it like so:

DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
Type myContentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.MyTypes.MyType");
DynamicContent myItem = dynamicModuleManager.CreateDataItem(myContentType);
var taxManager = TaxonomyManager.GetManager();
 
var divTaxon = taxManager.GetTaxa<Telerik.Sitefinity.Taxonomies.Model.HierarchicalTaxon>().SingleOrDefault(t => t.Name == divName && t.Taxonomy.Name == "divisions");
 
if (divTaxon != null)
    myItem.SetValue("Divisions", divTaxon.Id);
    dynamicModuleManager.SaveChanges();

and like so:

DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); 
Type myContentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.MyTypes.MyType");
DynamicContent myItem = dynamicModuleManager.CreateDataItem(myContentType);
var taxManager = TaxonomyManager.GetManager();
 
var divTaxon = taxManager.GetTaxa<Telerik.Sitefinity.Taxonomies.Model.HierarchicalTaxon>().SingleOrDefault(t => t.Name == divName && t.Taxonomy.Name == "divisions");
 
if (divTaxon != null)
    var divlist = myItem.GetValue<TrackedList<Guid>>("Division");
    divlist.Add(divTaxon.Id);
    myItem.SetValue("Division", divlist);
    dynamicModuleManager.SaveChanges();

 

The first example runs fine, but when I look at my content in the UI, the classification field is not set.  The second example (which I took from another forum post) throws an error.

Posted by Community Admin on 21-Oct-2014 00:00

Hello Michael,

You can set taxon via the AddTaxa method.

Example :

DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
            Type myContentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Test.Test");
            DynamicContent myItem = dynamicModuleManager.CreateDataItem(myContentType);
            var taxManager = TaxonomyManager.GetManager();
 
            var divTaxon = taxManager.GetTaxa<FlatTaxon>().Where(x => x.Name == "testTaxon").Single();
              
            if (divTaxon != null)
            
                myItem.Organizer.AddTaxa("Tags", divTaxon.Id);
                dynamicModuleManager.SaveChanges();
            



Regards,
Bobby
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed