… or Debugging Dynamics NAV “Any Client Control Add-Ins” as Microsoft seem to be calling them.
Debugging the Windows Client Control Add-ins is relatively easy using the Attach to Process feature of Visual Studio as described way back in 2009 by Christian. It is possible to sort-of do the same with Javascript Control Add-ins but once the Javascript files are actually running they have a different name so breakpoints don’t work as expected.
Below is an easier method which means you can control the debugger from the NAV end. In your Control Add interface class put the following function:
C# [ApplicationVisible] void StartDebugger();
In your Javascript file put this function:
Javascript function StartDebugger() { debugger; }
Then from NAV you can call this:
C/AL CurrPage.Ctrl.StartDebugger;
That’s it. When the Javascript debugger function is hit it will ask you which Script Debugger you want to use and load the correct file so you can set your breakpoints. If you need to set breakpoints in other Javascript files just add a function to them (making sure they have a unique function name)…
Javascript function Script2LoadtoDebugger() { return true; }
…then change then function in your main Javascript to call them and when the debugger starts you can Step-into that function to load the other file.
Javascript function StartDebugger() { debugger; Script2LoadtoDebugger; }
Hope this is helpful 😀
Nikolai
Thanks for this! It was helpful. Btw, do you have an idea of how to get rid of the “To help protect your security….” warning when starting the javascript control add in?
LikeLike
I haven’t had any issues with this, I did a quick search and found your post https://community.dynamics.com/nav/f/34/t/202997 where you mention it’s just when you run on the server?
Look at this thread which says the two approaches are basically to “allow” the blocked content (which I think you have tried) http://stackoverflow.com/questions/7038724/how-to-automaticaly-allow-blocked-content-in-ie
or alternatively try and mark the content so it is not blocked.
If it is only an issue when running on the server, then it might be to do with where NAV publishes the Javascript files and your permissions on these locations – if you open your browser debugging you should be able to see the addresses. But I’m just guessing, sorry I can’t help more.
LikeLike