Find element by an annotation from DocumentModel on Front-end side

Hello, I want to ask how to find an element from the given annotation from DocumentModel on the Front-end side

In the old a12 version, we have a method to find element by annotation like:

	static findElementsByAnnotation(documentModel: DocumentModel, annotation: string): Element[] {
		const groupIterator = new GroupIterator(documentModel.documentModelRoot);
		let elements: Element[] = [];
		for (let result = groupIterator.next(); !result.done; result = groupIterator.next()) {
			elements.push.apply(elements, result.value.elements.filter((e: Element) => e.annotations[annotation]));
		}
		return elements;
	}

I want to build a similar method in 2023.02 version, but I could not find the replacement of GroupIterator

Hi @hau-pure-spruce,

Can you please check the Reading annotations on validation rules in the document model topic, hopefully will help you.

Hi @ahmad-warm-vale, thank you for your reply, it doesn’t seem to resolve my problem :frowning:

Hi @hau-pure-spruce, how about this?

function findElementsByAnnotation(documentModel: DocumentModel, annotation: string): DocumentModel.Element[] {
    return documentModel.content.modelRoot.elements.filter(e => e.annotations?.[annotation])
}

@hau-pure-spruce: fyi, I created a corresponding ticket (see A12K-2981) to provide an API to deal with this situation.