Query filePath and EcInstanceId #8249
Answered
by
grigasp
zhang-zimin
asked this question in
Q&A
-
I'm working with iTwin.js and need to find the corresponding ECInstanceId and filePath for a given sourceElementId. After reviewing the documentation, I haven't found a direct API for this specific use case. Could you advise on the recommended approach? |
Beta Was this translation helpful? Give feedback.
Answered by
grigasp
Jun 25, 2025
Replies: 1 comment 1 reply
-
Hi @zhang-zimin. You will need to use an ECSQL query to get this information. To run the query on the frontend, you can use the IModelConnection.createQueryReader function. The query could look something like this: SELECT
a.Element.Id AS ITwinElementId,
COALESCE(
(
SELECT rl.Url
FROM bis.RepositoryLink rl
JOIN bis.ExternalSource es ON es.Repository.Id = rl.ECInstanceId
WHERE es.ECInstanceId = a.Source.Id
LIMIT 1
), (
SELECT rl.Url
FROM bis.RepositoryLink rl
JOIN bis.ElementHasLinks ehl ON ehl.TargetECInstanceId = rl.ECInstanceId
JOIN bis.Model m ON m.ModeledElement.Id = ehl.SourceECInstanceId
JOIN bis.Element e ON e.Model.Id = m.ECInstanceId
WHERE e.ECInstanceId = a.Element.Id
LIMIT 1
)
) AS FilePath
FROM bis.ExternalSourceAspect a
WHERE a.Identifier = '<your element identifier here>' CC @diegoalexdiaz in case the query can be improved. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
zhang-zimin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @zhang-zimin.
You will need to use an ECSQL query to get this information. To run the query on the frontend, you can use the IModelConnection.createQueryReader function.
The query could look something like this: