Happy new year, readers! Time for another Feynman technique exercise.
Today I tried for the first time (Duh Silviu …. it’s been out there for at least a year!!!) to debug a snapshot.
But first, what is a snapshot? A snapshot is a recording of executed code in Business Central.
The idea is that when you want to investigate an error in one of your environments (I’ll be showing screenshots of SaaS), you would start the recorder (from VS Code), perform the action you want to investigate, stop the recorder. Then re-play the recording. Simple!
Well, I ran into a few issues, therefore, for my sake in the future debugging sessions and for the interested readers, I’ll recap what I did to be able to replay a snapshot for debugging.
User debugging settings
First, the user that will connect to the SaaS for debugging purposes should be part of a group called D365 SNAPSHOT DEBUG:
Point Snapshot to the right environment
Most of SaaS development environments I come across have one configuration in launch.json.
For snapshot debugging though, you need an additional configuration:
I added the first configuration for this exercise.
The key element is the sessionId.
To find the sessionId you need to go to the admin console:
a) Navigate to https://businesscentral.dynamics.com/%5BTenantId%5D/admin and
b) Click on Environments
c) Launch action Sessions
e) Take note of your session
Note: This step is going to be a bit tricky. Because you might have plenty of sessions with BC and you might try to record the wrong session. I usually cancel all sessions under my name, close all BC windows, make sure there is no active session under my name, login in BC, check the session id, update configuration, and start recording.
In VS Code, start recording by pressing F7 or from the Pallette launch AL: Initialize Snapshot Debugging.
Play use case
In BC, play your use case.
For example, in my environment I had a Sales Order without External Document No.
Open the Sales Order and attempt to Post.
Get the error referring to the missing “External Document No.”.
Move then to VS Code to stop the recording.
In VS Code, stop recording. Use ALT + F7 or from the Pallette launch AL: Finish Snapshot debugging on the server. In the Output screen of the VS Code you should see something like this:
In VS Code, on the left side of the toolbar, there is a small button showing all snapshots.
Click on it, and from the top choose the desired snapshot, in my case last snapshot is the one on top:
After choosing the snapshot, the system will automatically play it, stopping through each breakpoint and ending up at the line of code responsible for the error encountered in the web client.
You can see on the left side all the goodies needed for debugging: the Call Stack, the local and global variables…
And if you are interested, you can unzip the snapshot and have a look at what is in it: a set of MDC files, AL files and a version file.
Hope this helps!