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

Forums / Developing with Sitefinity / Getting taxonomy associated with a dynamic content item

Getting taxonomy associated with a dynamic content item

7 posts, 0 answered
  1. Alain
    Alain avatar
    1 posts
    Registered:
    02 Mar 2013
    21 Aug
    Link to this post

    I created a dynamic module with lots of content. There is a detail page for each piece of content and on that detail page, I would like to list the taxonomy that the content item is associated with.  The module has many flat taxonomy references/fields (one to one and one to many's) plus some choice fields. 

    What I would like to know is how to get all (particular) taxonomy for a specific content item. So how do I get all taxonomy of type "datasources" for example? Here is my code thus far which does not seem to work

    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);

    Type measureType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.DataContent.Measure");

    DynamicContent measureItem = dynamicModuleManager.GetDataItem(measureType, measureID);

     var manager = TaxonomyManager.GetManager();
     var tags = measureItem.GetValue<TrackedList<Guid>>("compendiumdatasources");

    foreach (Guid itm in tags)
     {

         //itm.ToString() --- The GUID's I get are incorrect

    }

     

    Any advice on what I am doing wrong? Thanks so very much.

  2. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    22 Aug in reply to Alain
    Link to this post
    Hi Alain. You code looks fine. Why did you decide that GUID's returned from measureItem.GetValue<TrackedList<Guid>>("compendiumdatasources"); are incorrect?
  3. Alain
    Alain avatar
    1 posts
    Registered:
    02 Mar 2013
    22 Aug in reply to Victor Leontyev
    Link to this post

    Hi Victor, thank you for your reply. I guess where I go here from here might be the problem. When debugging, it seems that the "tags" (aka compendiumdatasources) is yielding no results even though they are associated with data in the backend. I've tried with other flat taxonomy fields for the same content and it has yielded the same results. All I get for "tags" is Telerik.OpenAccess.TrackedList`1[System.Guid]. Iterating through tags gives me nothing. 

    Thank you for your help.

     

  4. Alain
    Alain avatar
    1 posts
    Registered:
    02 Mar 2013
    22 Aug
    Link to this post
    This might be a bit more helpful.  Using a different flat taxonomy field, I was able to get a GUID returned. In this case E743BFDE-49BF-442A-896F-D2206E0FF41C. But I could not find this GUID in sf_taxa. So I looked up the dynamic content item and found the base_id. Then looked in the field table and found the dynamic content guid and found the 'val' does in fact match the above GUID 'E743BFDE-49BF-442A-896F-D2206E0FF41C'. But if I look for this GUID in sf_taxa it is not there, which would explain why I am not getting any results back, unless I am missing a relationship or a table somewhere?
  5. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    22 Aug in reply to Alain
    Link to this post

    It is not so straight forward to check dependencies in Sitefinity database. 

    Try to execute this source code:

    TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
    FlatTaxonomy tagTaxonomy = taxonomyManager.GetTaxonomies<FlatTaxonomy>().SingleOrDefault(t => t.Name == "TAXONOMY_DEVELOPER_NAME");
    var listOfTags = new List<string>();
    var tags = measureItem.GetPropertyValue<TrackedList<Guid>>("compendiumdatasources");
                foreach (var tagId in tags)
                {
     
                    Taxon tag = tagTaxonomy.Taxa.SingleOrDefault(x => x.Id == tagId);
                    if (tag != nul)
                    {
                        listOfTags.Add(tag.Title);
                    }
                }

     

  6. Alain
    Alain avatar
    1 posts
    Registered:
    02 Mar 2013
    22 Aug
    Link to this post

    Victor, thanks for your continued help!

    I assumed that "TAXONOMY_DEVELOPER_NAME" is the machine name for the flat taxonomy I created, right? In this case, it is "compendium-data-sources". The other thing is that measureItem.GetPropertyValue was not valid so I used measureItem.GetValue. Am I missing something here?  still I am not getting any results, unfortunately.

    It must be related somehow though as in the backend it pulls up just fine. When editing the content, all the relationships are there and accurate.

    Thanks again!

  7. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    24 Aug in reply to Alain
    Link to this post

    Is your measuteItem object have Master or Live version? (Reference how to receive master or live http://docs.sitefinity.com/for-developers-query-master-and-live-versions)

    I think that the reason why you cant receive taxonomies. Please try to receive item with Live version and get tags for this object

7 posts, 0 answered