Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Log script errors on Application Insights

(0) ShareShare
ReportReport
Posted on by 30

Hi all,

I'm trying to use Application Insights to log form/script errors from my Dynamics 365 instance but they're not being tracked.

I started by creating an Application Insights resource in Azure and adding the following JavaScript (extracted from the Getting Started section from the App Insights Resource) to my CRM form (just like this walkthrough):

var appInsights=window.appInsights||function(config){
function i(config) { t[config] = function () { var i = arguments; t.queue.push(function () { t[config].apply(t, i) }) } }var t={config:config},u=document,e=window,o="script",s="AuthenticatedUserContext",h="start",c="stop",l="Track",a=l+"Event",v=l+"Page",y=u.createElement(o),r,f;y.src=config.url||"az416426.vo.msecnd.net/.../ai.0.js";u.getElementsByTagName(o)[0].parentNode.appendChild(y);try{t.cookie = u.cookie}catch(p){}for(t.queue=[],t.version="1.0",r=["Event","Exception","Metric","PageView","Trace","Dependency"];r.length;)i("track"+r.pop());return i("set"+s),i("clear"+s),i(h+a),i(c+a),i(h+v),i(c+v),i("flush"),config.disableExceptionTracking||(r="onerror",i("_"+r),f=e[r],e[r]=function(config,i,u,e,o){var s=f&&f(config,i,u,e,o);return s!==!0&&t["_"+r](config,i,u,e,o),s}),t
    }({
            instrumentationKey:"XXXXX"
    });

    window.appInsights=appInsights;
    appInsights.trackPageView();

After this, I started to see data related to page views and page load times so the tracking is enabled:

page_5F00_views.png

My next action was then to force some script errors in the form to visualize then in Azure. In order to do this, I added a JavaScript function in the OnChange event of a field to get an "undefined" error:

undefined_5F00_error_5F00_crm.PNG

As you can see in the previous image, the error is being thrown in D365 as expected but there's no record of it in Application Insights. After some tests I started to suspect that CRM is catching that error and not letting it to reach the browser (the error doesn't appear in the console). To confirm my suspicions, I created a HTML web page with the same App Insights configuration and I simulated the error to see if in that scenario the errors are being tracked and the answer is yes:

appinsights_5F00_undefined.PNG

So it seems that Dynamics is "swallowing" the error and preventing it to be logged. Have anyone faced this issue before? Is there a workaround that I can use to successfully track the errors into App Insights?

Thanks!

*This post is locked for comments

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans