Have you worked on a content hub implementation where you needed to create too may taxonomies definitions? did you need to loop your client in the process of updating these taxonomies and their translations? how would you get a list of created taxonomies (Definition Names)? you probably checked the UI and you figured out already that there is no way to do that OOTB, if you didn't get into this case before you probably going to in future, its very simple to accomplish this with Content Hub Scripts. keep reading!
Then once you know how to do that, you can filter the list of taxonomies out of the entity definitions retrieved, following is a content hub script you can use to do the job, it will create an entity definitions iterator which will go through all entity definitions then you can just filter the taxonomies:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
var entityDefinitions = new List<IEntityDefinition>(); | |
var entityDefinitionIterator = MClient.EntityDefinitions.CreateEntityDefinitionIterator(); | |
while (entityDefinitionIterator.CanMoveNext()) | |
{ | |
await entityDefinitionIterator.MoveNextAsync(); | |
entityDefinitions.AddRange(entityDefinitionIterator.Current.Items); | |
} | |
var customTaxonomyNames = entityDefinitions.Where(ed => | |
ed.IsTaxonomyItemDefinition).Select(ed => ed.Name); | |
var names = string.Join("\n", customTaxonomyNames.Select(ed => ed)); | |
MClient.Logger.Info(names); |
Another tip I can provide, you can also filter the list based on a creator user, like if you want to retrieve a list created by or not created by a specific user, following is what you can do:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var customTaxonomyNames = entityDefinitions.Where(ed => | |
ed.IsTaxonomyItemDefinition && ed.CreatedBy.HasValue && ed.CreatedBy != 6).Select(ed => ed.Name); |
Hopefully the above was helpful!
No comments:
Post a Comment