Getting taxonomy associated with a dynamic content item

Posted by Community Admin on 04-Aug-2018 23:13

Getting taxonomy associated with a dynamic content item

All Replies

Posted by Community Admin on 21-Aug-2016 00:00

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.

Posted by Community Admin on 22-Aug-2016 00:00

Hi Alain. You code looks fine. Why did you decide that GUID's returned from measureItem.GetValue<TrackedList<Guid>>("compendiumdatasources"); are incorrect?

Posted by Community Admin on 22-Aug-2016 00:00

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.

 

Posted by Community Admin on 22-Aug-2016 00:00

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?

Posted by Community Admin on 22-Aug-2016 00:00

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);
                
            

 

Posted by Community Admin on 22-Aug-2016 00:00

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!

Posted by Community Admin on 24-Aug-2016 00:00

Is your measuteItem object have Master or Live version? (Reference how to receive master or live 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

This thread is closed