This repository has been archived by the owner. It is now read-only.

Retrieve terms from Taxonomy Termstore Termset #415

Closed
deanbot opened this Issue Apr 13, 2017 · 5 comments

Comments

Projects
None yet
5 participants
@deanbot

deanbot commented Apr 13, 2017

Greetings

Category

[* ] Enhancement

Expected / Desired Behavior / Question

I believe pnp-js-core would benefit from methods for retrieving termsets in a termstore similar to those for querying for list items.

The old behavior worked much like this:

SP.SOD.executeOrDelayUntilScriptLoaded(function() {

  // get individual term
  SP.SOD.executeOrDelayUntilScriptLoaded(function() {
    var ctx = new SP.ClientContext.get_current(),
    session = SP.Taxonomy.TaxonomySession.getTaxonomySession(ctx),
    termStore = session.getDefaultSiteCollectionTermStore();
    term = termStore.getTerm('c05df22b-f88d-46a9-846b-a1802f181320');
    ctx.load(term);
    ctx.executeQueryAsync(function() {
      console.log(term)
    });
  }, 'SP.Taxonomy.js');

  // get terms from termset
  SP.SOD.executeOrDelayUntilScriptLoaded(function() {
    var ctx = new SP.ClientContext.get_current(),
    session = SP.Taxonomy.TaxonomySession.getTaxonomySession(ctx),
    termStore = session.getDefaultSiteCollectionTermStore();
    termSet = termStore.getTermSet('c05df22b-f88d-46a9-846b-a1802f181320'),
    terms = termSet.get_terms();
    ctx.load(terms);
    ctx.executeQueryAsync(function() {
      var enumerator = terms.getEnumerator();
      while (enumerator.moveNext()) {
        console.log(enumerator.get_current());
      }
    });
  }, 'SP.Taxonomy.js');

}, 'SP.js');

I work a lot with termstores for creating navigational components. One important component to this is the ability to create child terms to make a hierarchical navigational structure. Thus the ability to iterate over terms within terms is critical.

An example in sp-pnp-js (note i'm not using TS) could be:

import { TermStore } from 'sp-pnp-js';

// get term
new TermStore('/sites/mySite').terms.getById('c05df22b-f88d-46a9-846b-a1802f181320').get()
  .then(term => console.log(term));

// get termSet
new TermStore('/sites/mySite').termSet.getById('c05df22b-f88d-46a9-846b-a1802f181320').get()
  .then(termSet => console.log(termSet));

// loop through terms in termset and child terms
new TermStore('/sites/mySite').termSet.getById('c05df22b-f88d-46a9-846b-a1802f181320').terms.get()
  .then(terms => {
    for (let i=0; i< terms.length; i++) {
      console.log(terms[i]);
      let childTerms = term.terms.get().then(childTerms => console.log(childTerms));
      // or call termStore.termSet.getById().terms again
    }
  })

@deanbot deanbot changed the title from Retrieve items from Taxonomy Termstore Termset to Retrieve terms from Taxonomy Termstore Termset Apr 13, 2017

@koltyakov

This comment has been minimized.

Show comment
Hide comment
@koltyakov

koltyakov Apr 13, 2017

Collaborator

Unfortunately, there is no REST API for MMD.
I'm not sure that using JSOM follows ideology behind PnP-JS-Core as a REST API wrapper.
Though, it's possible to use JSOM in non-browser JS too by sending packages to /_vti_bin/client.svc/ProcessQuery. I achieved MMD communication within server-side JS which works nicely. But it can be unpredictably complex to maintain.
Interesting to hear from @patrick-rodgers about the topic. In some way, it's close to Graph consumption (which has been discussing in another issue) and it can be the try to make library larger than it was initially aimed to be. But, this tells about the great demand. And it's cool!

Collaborator

koltyakov commented Apr 13, 2017

Unfortunately, there is no REST API for MMD.
I'm not sure that using JSOM follows ideology behind PnP-JS-Core as a REST API wrapper.
Though, it's possible to use JSOM in non-browser JS too by sending packages to /_vti_bin/client.svc/ProcessQuery. I achieved MMD communication within server-side JS which works nicely. But it can be unpredictably complex to maintain.
Interesting to hear from @patrick-rodgers about the topic. In some way, it's close to Graph consumption (which has been discussing in another issue) and it can be the try to make library larger than it was initially aimed to be. But, this tells about the great demand. And it's cool!

@patrick-rodgers

This comment has been minimized.

Show comment
Hide comment
@patrick-rodgers

patrick-rodgers Apr 14, 2017

Contributor

We hear this request a lot, and understand there is a need - but as @koltyakov points out there is not REST api for this. I want to stay away from crafting requests to client.svc directly as that will be a giant mess to maintain and would create a second code base for processing requests. You can add your votes to this user voice that is already tagged as thinking about it. More votes does result in higher priority.

As soon as there is native support for REST management of taxonomy we'll get it added, but that is the path I want to stay on.

Contributor

patrick-rodgers commented Apr 14, 2017

We hear this request a lot, and understand there is a need - but as @koltyakov points out there is not REST api for this. I want to stay away from crafting requests to client.svc directly as that will be a giant mess to maintain and would create a second code base for processing requests. You can add your votes to this user voice that is already tagged as thinking about it. More votes does result in higher priority.

As soon as there is native support for REST management of taxonomy we'll get it added, but that is the path I want to stay on.

@jonathanhotono

This comment has been minimized.

Show comment
Hide comment
@jonathanhotono

jonathanhotono May 5, 2017

+3 vote for the user voice as I also work heavily using taxonomy term store api. The other way around is to use the unpublished api that microsoft used by default in the term store page which also not recommended.

+3 vote for the user voice as I also work heavily using taxonomy term store api. The other way around is to use the unpublished api that microsoft used by default in the term store page which also not recommended.

@harshdamaniahd

This comment has been minimized.

Show comment
Hide comment
@harshdamaniahd

harshdamaniahd Apr 11, 2018

This doesnt work in pnp as well ?
I am using latest version of code ?

This doesnt work in pnp as well ?
I am using latest version of code ?

@patrick-rodgers

This comment has been minimized.

Show comment
Hide comment
@patrick-rodgers

patrick-rodgers May 15, 2018

Contributor

Going to close this as part of house keeping moving towards EOL for this library in July 2018.

Thank you for your interest in the sp-pnp-js library. We wanted to mention that this library is being deprecated in July, 2018 in favor of the new scoped pnpjs libraries. You should begin transitioning your existing projects when possible, or start new projects with the new libraries. Please see the transition guide for more details on migrating and be sure to let us know if you have any questions. Thanks!

Contributor

patrick-rodgers commented May 15, 2018

Going to close this as part of house keeping moving towards EOL for this library in July 2018.

Thank you for your interest in the sp-pnp-js library. We wanted to mention that this library is being deprecated in July, 2018 in favor of the new scoped pnpjs libraries. You should begin transitioning your existing projects when possible, or start new projects with the new libraries. Please see the transition guide for more details on migrating and be sure to let us know if you have any questions. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.