sm-rob
(Robert Shaw)
April 29, 2025, 3:23pm
1
Hello all.
I am building a property editor that takes some information from the parent node.
For reference, my tree looks something like this:
My property editor is on News item node and I am trying to get the ID of the parent (“News”).
In earlier versions on Umbraco I was able to do this by using the editorState.
editorState.current.parentId
Is there a way I can get the Parent Id inside of my new Lit custom property editor?
Thank you,
Rob
LuukPeters
(Luuk Peters (Proud Nerds))
April 30, 2025, 6:36am
2
I think you can use the docment workspace context:
import { UMB_DOCUMENT_WORKSPACE_CONTEXT, UmbDocumentWorkspaceContext } from '@umbraco-cms/backoffice/document';
export default class ExampleAppView extends UmbElementMixin(LitElement)
{
#entityContext?: UmbDocumentWorkspaceContext;
...
constructor() {
this.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, async (instance) => {
this.#entityContext = instance;
this.observe(this.#entityContext.parentUnique, async (unique) => {
if (unique)
//Do something with it
});
}
}
...
}
sm-rob
(Robert Shaw)
April 30, 2025, 2:17pm
3
Hello Luuk.
Thank you for your reply! Appreciate it.
I am using ‘umbraco/backoffice’ version 15.3.0 and unfortunately “unique” is undefined for me. Is this something you’ve used in your work?
I assume there is no issue with consuming other Contexts (as I am doing) in the constructor, that would cause any issue here or anything silly like that?
I’ll continue to try alternative methods.
Thanks again Luuk,
Rob
sm-rob
(Robert Shaw)
May 1, 2025, 12:07pm
5
Hello.
Just as a follow up for anyone else. I’ve managed to get the parent id of the document I am on, by using UmbDocumentItemRepository’s .requestItems() method.
import { UmbDocumentItemRepository } from '@umbraco-cms/backoffice/document';
...
#itemRepository = new UmbDocumentItemRepository(this);
Then in my function I can do something like this:
const unique = '62f61707-9b73-4663-ab07-900ed411b4ed';
const { data } = await this.#itemRepository.requestItems([unique]);
const parentId = data[0].parent?.unique
Working for now, but I don’t think this is probably the best way. The UmbDocumentWorkspaceContext didn’t seem to have “parentUnique”.
Thank you,
Rob
Hi @sm-rob
I looked a bit at this and there is an issue present here.
It turns out that the Workspace parentUnique
only has a value when creating a new document. but When loading one it does not get set, so if you don’t mind please create an issue regarding this.
Thanks in advance
1 Like
sm-rob
(Robert Shaw)
May 1, 2025, 4:18pm
7
Thank you again @nielslyngsoe
I have created an issue here:
opened 04:15PM - 01 May 25 UTC
type/bug
### Which Umbraco version are you using?
15.1.1
### Bug summary
When trying t… o get the parent unique (id) of the current document using the document workspace context (UmbDocumentWorkspaceContext). I am getting undefined returned.
### Specifics
`parentUnique` is set when creating a new document, but **not** when a document is loaded.
A more detailed forum post can be found here:
https://forum.umbraco.com/t/retrieving-id-unique-of-the-current-pages-parent/3169
Unfortunately I do not have a live example of the issue.
As of testing, my package.json file includes:
`"@umbraco-cms/backoffice": "^15.3.0-rc2",`
### Steps to reproduce
Create a custom property editor. As seen below.
```typescript
import {UMB_DOCUMENT_WORKSPACE_CONTEXT, UmbDocumentWorkspaceContext} from "@umbraco-cms/backoffice/document"
export default class ExampleAppView extends UmbElementMixin(LitElement) {
#entityContext?: UmbDocumentWorkspaceContext;
constructor() {
this.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, async (instance) => {
this._entityContext = instance;
this.observe(this.#entityContext.parentUnique, async (unique) => {
if (unique)
//Do something with it
});
}}}'
```
`"unique"` is undefined as a result of `this.#entityContext.parentUnique` being undefined.
### Expected result / actual result
The result should return the `unique` id for the parent of the current node.
All the best,
Rob
1 Like