tryGetElement Method

Get an element by Id, FederationGuid, or Code

tryGetElement<T extends Element<T>>(elementId: string | Code | ElementLoadProps, elementClass?: EntityClassType<Element>): undefined | T

@returns The element or undefined if the element is not found or fails validation when elementClass is specified.

@throws IModelError if the element exists, but cannot be loaded.

@note Useful for cases when an element may or may not exist and throwing an Error would be overkill.

@see IModelDb.Elements.getElement

Parameter Type Description
elementId string | Code | ElementLoadProps either the element's Id, Code, or FederationGuid, or an ElementLoadProps
elementClass EntityClassType<Element> Optional class to validate instance against. This parameter can accept abstract or concrete classes, but should be the same as the template (T) parameter.

Returns - undefined | T

The element or undefined if the element is not found or fails validation when elementClass is specified.

Defined in

Last Updated: 25 April, 2024