SubPointSolutions / spmeta2

SharePoint artifact provision for .NET platform. Supports SharePoint Online, SharePoint 2019, 2016 and 2013 via CSOM/SSOM.
http://subpointsolutions.com/spmeta2
133 stars 56 forks source link

Create child TaxonomyTermDefinition #1126

Closed VerdonTrigance closed 5 years ago

VerdonTrigance commented 5 years ago

Hello, guys. Is it possible to provision TaxonomyTermDefinition with child TaxonomyTermDefinition through StandardSSOMProvisionService for example?

I have seen this: http://docs.subpointsolutions.com/spmeta2/reference/sp-standard-definitions/taxonomytermdefinition.html but there is no child terms in other terms.

Like this:

var model = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddTaxonomyTermStore(defaultSiteTermStore, termStore =>
                {
                    termStore.AddTaxonomyTermGroup(someGroup, group =>
                    {
                        group.AddTaxonomyTermSet(firstTermSet, termSet =>
                        {
                            termSet.AddTaxonomyTerm(term, parentTerm =>
                            {
                                 parentTerm.AddTaxonomyTerm(childTerm, and so on ....)
                            });
                        });
                    });
                });
            });
SubPointSupport commented 5 years ago

Hello @VerdonTrigance ,

Term nesting is fully supported for both CSOM/SSOM, and it works exactly as you showed - by nesting . AddTaxonomyTerm() one under the other.

A few examples can be found in the regression test, here is how it works for both CSOM/SSOM:

https://github.com/SubPointSolutions/spmeta2/blob/master/SPMeta2/SPMeta2.Regression.Tests/Impl/Scenarios/TaxonomyTermScenariousTest.cs#L219-L220

If that isn't what you are after, let us know what the exact problem and target scenario would be.

VerdonTrigance commented 5 years ago

@SubPointSupport thank you for reply and example. It usage quite strange. How to add term6 under term4 in that example? There is no second argument in function.

SubPointSupport commented 5 years ago

@VerdonTrigance no worries.

.AddTaxonomyTerm() is an extenion method under "SPMeta2.Standard.Syntax" namespace.

It just might be that VS or VSCode does not see this method. ReSharper or latest VisualStudio automatically resolves namespaces making sure that extension methods are available.

Here is the method definition:

https://github.com/SubPointSolutions/spmeta2/blob/5d5121e61f45a59a95589f945047a84d9bc9ccd4/SPMeta2/SPMeta2.Standard/Syntax/Taxonomy/TaxonomyTermDefinitionSyntax.cs

Give it a try by adding "using SPMeta2.Standard.Syntax;", check if the method is available. Adding terms under terms is a matter of constructing the object tree. SPMeta2 provides an API to craft such an object tree.

Let's use doco example you shared early:

http://docs.subpointsolutions.com/spmeta2/reference/sp-standard-definitions/taxonomytermdefinition.html

What you want to do is most likely looks like this:

using SPMeta2.Standard.Syntax;
...
...

var model = SPMeta2Model.NewSiteModel(site =>
{
    site.AddTaxonomyTermStore(defaultSiteTermStore, termStore =>
    {
        termStore.AddTaxonomyTermGroup(clientsGroup, group =>
        {
            group
                .AddTaxonomyTermSet(smallBusiness, termSet =>
                {
                    termSet.AddTaxonomyTerm(subPointSolutions);
                })
                .AddTaxonomyTermSet(mediumBusiness)
                .AddTaxonomyTermSet(enterpriseBusiness, termSet =>
                {
                    termSet
                        .AddTaxonomyTerm(microsoft, msTermNode => {
                             // msTermNode <- this is actual "microsoft" term added early
                             // let's add apple term under microsoft term
                             // we use extension method resolving model tree node, moving down
                             msTermNode.AddTaxonomyTerm(apple, appleTermNode => {
                                 // appleTermNode <- this is actual "apple" term added under "microsoft" term
                                 // same-same, extention method, one level down
                                 appleTermNode.AddTaxonomyTerm(oracle);

                             });
                         })
                        .AddTaxonomyTerm(apple)
                        .AddTaxonomyTerm(oracle);
                });
        });
    });
});

Hope that helps. If not - just share the term tree - how you'd like it to see, we'll translate into SPMeta2 model for you.

VerdonTrigance commented 5 years ago

Thank you. I will check what namespace I was using tomorrow and post a feedback. I wanted such structure under termset Shops: country - region - city - shop1, shop2, so on. PS: sorry, I’m typing from the phone.

SubPointSupport commented 5 years ago

Then it should work well. Give it a go, let us know how it goes.

VerdonTrigance commented 5 years ago

Hi. I have checked this and it is working as u sayed. I can’t tell what namespace I used before, but anyway now it works as expected. Thank you