MS Code review clarification on document.getElementById in html

Soona Kumar 0 Reputation points
2025-09-24T07:00:03.9666667+00:00

Related to MS code review, We got " The call accesses the HTML document object model (DOM) directly. This technique is unsupported. Remove or replace with a supported API provided in the client object model or employ a different technique." in one of our RunCanvasApp.html file. We were using document.getElementById. We have seen one of the thread that use of getElementByID to access any DOM element within your web resource content is supported. So can we consider this as false positive?

Developer technologies | .NET | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Adiba Khan 895 Reputation points Microsoft External Staff
    2025-09-24T09:33:28.93+00:00

    The issue:

    ·         The MS code review flagged this line: “The call accesses the HTML document object model (DOM) directly. This technique is unsupported. Remove or replace with a supported API provided in the client object model or employ a different technique.”

    ·         This happens because in certain contexts (like Power Apps, Dynamic 365, or other Microsoft platforms), direct DOM manipulation (document.getElementById, document.querySelector, etc.) is not recommended or supported.

    ·         Instead, Microsoft wants developers to use their client APIs (like Xrm in Dynamic 365, or PCF control APIs in Power App).

    Why?

    ·         Direct DOM access can break if Microsoft updates their platform UI.

    ·         DOM IDs/classes may change, and your code will break since it depends on internal HTML structure.

    ·         Using official client APIs makes your solution more stable and supported long-term.

    Can this be false positive?

    ·         If you are working in a standalone web app (not inside Dynamics/Power Apps or similar), then yes document.getElementById is completely fine and supported in browsers.

    ·         But if your HTML/JS is used as a web resource inside Microsoft environments, then it’s not a false positive. Microsoft requires you to use their APIs instead of touching the DOM directly.

    Summary:

    ·         If you are building a normal web app-> safe to ignore, this is a false positive.

    ·         If you are inside Microsoft environments (Dynamic, Power Apps, etc.) -> you should avoid document.getElementById and instead use the supported client API for interacting with forms or UI elements.

     

    Let me know if you need any further help with this. We'll be happy to assist.

    If you find this helpful, please mark this as answered.

     


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.