+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Apply custom classification to Dynamic Content Items

Apply custom classification to Dynamic Content Items

2 posts, 0 answered
  1. BoaMike
    BoaMike avatar
    51 posts
    Registered:
    25 Sep 2009
    16 Oct 2014
    Link to this post

    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.
  2. Bobby
    Bobby avatar
    10 posts
    Registered:
    22 Nov 2016
    21 Oct 2014
    Link to this post
    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
     
2 posts, 0 answered