Pnpjs: Unable to access parent of term : @pnp/taxonomy

Created on 1 Jun 2018  路  12Comments  路  Source: pnp/pnpjs

I am trying to access parent of a term , but it doesnot work ?

parsers.ts:46 Uncaught (in promise) Error: {"ErrorMessage":"Field or property \"Parent\" does not exist.","ErrorValue":null,"TraceCorrelationId":"97da6c9e-800b-5000-cea4-1abc552e9906","ErrorCode":-1,"ErrorTypeName":"Microsoft.SharePoint.Client.InvalidClientQueryException"}
at parsers.ts:46

// load the data into the terms instances
const termsWithData = set.terms.get();
console.log(termsWithData);
termsWithData.then((data)=>{
  const a = data[0].Id.split("(")[1].split(")")[0];
  var t = data[0].parent.get().then((f)=>{
    console.log(f.Name + f.Id)

  });

})


  }
code answered question

Most helpful comment

Hey guys,

One can get terms with parents in a single call like this:

const terms = await set.terms.select('Id', 'Name', 'Parent').get();

image

All other required props can be provided in .select.

Currently, IFAIK, selectable props can't contain sub props, like 'Parent.Id'. Or I might be wrong and @patrick-rodgers may correct me.

Having a term Id, its parent can be requested with:

const parentTerm = await store.getTermById('3dbb2701-3c8b-42e9-9cdd-6a7cc5d877f1').parent.get();

Hope this helps.

All 12 comments

I was just trying to do something pretty similar and was receiving the same error.

I鈥檓 trying to figure out the easiest way to build up the term set hierarchy.

Yes actually, so if the hierarchy is A-B-C-D
Where D is child of C and C is child of B and B is child of A and A is parent
In this way from last child D I need to traverse up getting the parent of each term.
Let me know if anything works?

Yeah, I don鈥檛 think the terms necessarily come back in that order though, so not sure you can rely on that. If you could get the parent though the idea was matching the term up with the ID.

But I had the same issue as you and couldn鈥檛 get the parent details.

In the console , i get this where for parent the information is missing
image

I have borrowed the solution from below link back in the days and that one utilizes the PathOfTerm property:

https://www.habaneroconsulting.com/stories/insights/2014/returning-a-sharepoint-2013-termset-in-a-tree-structure-using-javascript

...I'm pretty sure you cant get the Parent without doing an extra call to the service so most tree solutions leverages the PathOfTerm property

/BR Fredrik

I can get path, but I don't get the guid.
You can download the API and try..it doesn't work

Oh i see now, well my suggestion would be to skip the parent property and instead "calculate" the tree based on the other property, PathOfTerm. With a big tree performance could be an issue with the extra calls.

I found another solution also using PathOfTerm, should be possible to re-implement based on either of those two:

https://www.agates.io/loading-terms-as-a-tree-from-sharepoint-online.html

...but I would also expect to get the ID from how you did it no question about that...

Hey guys,

One can get terms with parents in a single call like this:

const terms = await set.terms.select('Id', 'Name', 'Parent').get();

image

All other required props can be provided in .select.

Currently, IFAIK, selectable props can't contain sub props, like 'Parent.Id'. Or I might be wrong and @patrick-rodgers may correct me.

Having a term Id, its parent can be requested with:

const parentTerm = await store.getTermById('3dbb2701-3c8b-42e9-9cdd-6a7cc5d877f1').parent.get();

Hope this helps.

Thanks @koltyakov let me try and get back to you soon.
And appreciate the reply

@koltyakov thanks for pointing out it was possible in a single call - in that case it makes more sense to go with parent id rather than path - cool, thanks!

Thanks all, going to close this as answered. If you have additional questions on this topic please _reopen_ the thread. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KieranDaviesV picture KieranDaviesV  路  3Comments

simonagren picture simonagren  路  3Comments

Holden15 picture Holden15  路  3Comments

SpliceVW picture SpliceVW  路  3Comments

SpliceVW picture SpliceVW  路  3Comments