Hi, Readers.
I attended the Business Central Office Hours Calls (Snapshot Debugging) last night, so today I would like to talk about Snapshot Debugging in Business Central and share some information. Hope this will help.
![](https://yzhums.com/wp-content/uploads/2021/05/image-119-1024x517.png)
Snapshot debugging allows a delegated admin to record AL code that runs on the server, and once it has run, debug the recorded snapshot in Visual Studio Code. For a delegated admin to create and download a snapshot file that exists on the server on behalf of an end-user, the delegated admin must be part of the D365 Snapshot Debug permission group.
![](https://yzhums.com/wp-content/uploads/2021/05/image-123-1024x449.png)
With Business Central 17.2 – Snapshot Debugging is available in production cloud environments.
From Visual Studio Code, you start a snapshot by creating a snapshot configuration file. There are two template configurations for a snapshot, which are accessed by selecting Add Configuration in Visual Studio Code.
- AL: Initialize a snapshot debugging session locally
- AL: Initialize a snapshot debugging session on cloud
![](https://yzhums.com/wp-content/uploads/2021/05/image-116.png)
You can choose whether to run the session on a cloud service or locally.
![](https://yzhums.com/wp-content/uploads/2021/05/image-117.png)
The configuration file will now contain the following information:
Setting | Description |
---|---|
userId | The GUID of the user on whose behalf a snapshot debugging will be started. For on-premises, this can also be the user name in user password authentication scenarios. The user must be able to start, or have a session type opened that is specified in the breakOnNext parameter. For more information, see JSON Files. |
sessionId | A session ID for the user specified above in userId . |
snapshotVerbosity | Determines how much execution context to be recorded. If SnapPoint is specified, then only methods that hit a snappoint will be recorded. |
Session ID:
![](https://yzhums.com/wp-content/uploads/2021/05/image-120.png)
User ID:
![](https://yzhums.com/wp-content/uploads/2021/05/image-152.png)
You can get the session ID and User ID in Business Central admin center.
![](https://yzhums.com/wp-content/uploads/2021/05/image-118.png)
When a configuration is defined, a snapshot debugging session can be initialized by pressing Ctrl+Shift+P and then selecting AL: Initialize Snapshot Debugging or by pressing F7.
![](https://yzhums.com/wp-content/uploads/2021/05/image-121-1024x353.png)
Snapshot debugging keyboard shortcuts:
Keyboard Shortcut | Action |
---|---|
F7 | Start a snapshot debugging session |
Shift+F7 | List all available snapshots |
Alt+F7 | Finish a snapshot debugging session |
To record the AL execution, the server will now wait for a connection to happen where the following rules apply:
- If a
sessionId
is specified for a userId for a given tenant then it will be that session that will be snapshot debugged. - If only a
userId
is specified for a given tenant then the next session that is specified in thebreakOnNext
configuration parameter is snapshot debugged. - If no
userId
is specified then the next session on a given tenant that validates thebreakOnNext
parameter will be snapshot debugged.
Okay, let’s try it.
The following is my test code.
![](https://yzhums.com/wp-content/uploads/2021/05/image-124.png)
If you choose Copy Customer, you will get a error.
![](https://yzhums.com/wp-content/uploads/2021/05/image-125-1024x386.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-126-1024x464.png)
Go back to VS Code, pressing Ctrl+Shift+P and then selecting AL: Initialize Snapshot Debugging or by pressing F7.
![](https://yzhums.com/wp-content/uploads/2021/05/image-127-1024x282.png)
Choose the snapshotInitialize set in launch.json. (If there is only one, no need to choose)
![](https://yzhums.com/wp-content/uploads/2021/05/image-128-1024x202.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-129.png)
The number after the debug icon on the status bar will be 1, and if you click on this icon (or pressing Shift + F7) a list of available snapshots is listed:
![](https://yzhums.com/wp-content/uploads/2021/05/image-130.png)
Select it to start the snapshot debugging session.
![](https://yzhums.com/wp-content/uploads/2021/05/image-131-1024x251.png)
Initialized -> Started
![](https://yzhums.com/wp-content/uploads/2021/05/image-153.png)
PS: Status of a snapshot debugging session
- Initialized – A request is issued and the server is waiting for the next session to be snapshot debugged based on the above rules.
- Started – You have attached to an end-user session to snapshot debug.
- Finished – When the snapshot debugging session has finished.
- Downloaded – When the snapshot file is downloaded.
Now, you can go back to Business Central to start the scenario that has been failing and needs troubleshooting.
![](https://yzhums.com/wp-content/uploads/2021/05/image-122-1024x386.png)
When the scenario is finished, you can press Ctrl+Shift+P and then select AL: Finish snapshot debugging on the server or by pressing ALT + F7.
![](https://yzhums.com/wp-content/uploads/2021/05/image-132.png)
The snapshot is downloaded as a ZIP file to the .snapshots folder in your VS Code project. And the debug icon on the status bar will be orange now.
![](https://yzhums.com/wp-content/uploads/2021/05/image-133-1024x545.png)
By clicking on debug icon, you can see the list of the downloaded snapshots.
![](https://yzhums.com/wp-content/uploads/2021/05/image-134-1024x228.png)
Select the snapshot and start the Snapshot Debugging:
![](https://yzhums.com/wp-content/uploads/2021/05/image-135-1024x545.png)
Complete Test Video:
PS: Breakpoints can be added and removed and they will be hit if given a breakpoint; the breakpoint is in the execution context of a recorded state. This means that if walking the execution stack for a breakpoint and the next stepped line is reached, then the code will break on the breakpoint.
![](https://yzhums.com/wp-content/uploads/2021/05/image-136.png)
You can also set breakpoints in Base Application (dal file).
![](https://yzhums.com/wp-content/uploads/2021/05/image-137.png)
For example:
![](https://yzhums.com/wp-content/uploads/2021/05/image-154-1024x547.png)
Information about Snapshot Debugging from Microsoft: You can also find the latest recordings here: https://aka.ms/BCOfficeHoursRecordings (allow for up to 48 hours for it to be accessible)
![](https://yzhums.com/wp-content/uploads/2021/05/image-138-1024x427.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-139-1024x456.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-140-1024x536.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-141-1024x512.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-142-1024x545.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-143-1024x515.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-144-1024x500.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-145-1024x545.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-146-1024x478.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-147-1024x520.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-148-1024x544.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-149-1024x506.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-150-1024x544.png)
![](https://yzhums.com/wp-content/uploads/2021/05/image-151-1024x547.png)
Find out more about Snapshot Debugging from Microsoft Docs.
You can view the session on Visual Studio Code and AL from Release wave 2 2020 prior to the call: Dynamics 365 Partner Portal (microsoft.com).
Update 2022/09/12: Business Central 2022 wave 2 (BC21) new features: Visualize code lines executed in snapshot capture (Snapshot Debugger Lines Hit Decoration)
END
Hope this will help.
Thanks for reading.
ZHU
コメント