Retrieving ID/Unique of the current pages parent

Hello all.

I am building a property editor that takes some information from the parent node.

For reference, my tree looks something like this:

  • News
    – News item

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

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
			});
		}
	}
	...
}

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

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 :slight_smile:

1 Like

Thank you again @nielslyngsoe

I have created an issue here:

All the best,
Rob

1 Like