tryGetElement Method
Get an element by Id, FederationGuid, or Code
tryGetElement<T extends Element>(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 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
- core/backend/src/IModelDb.ts Line 1818
Last Updated: 14 November, 2024
Found something wrong, missing, or unclear on this page?Raise an issue in our repo.