This was the first time I was going to debug against a sandbox it it wasn’t as smooth as I thought as it was with OnPrem. The reason for that is that the user id must be the GUID for the user name in BC.
First step is adding a new snapshot configuration for cloud in launch.json
This gives you the following
{
"name": "snapshotInitialize: Microsoft production cloud",
"type": "al",
"request": "snapshotInitialize",
"environmentType": "Production",
"environmentName": "production",
"breakOnNext": "WebClient",
"executionContext": "DebugAndProfile"
},
Now we need to change the environmentType if it is production we would like to debug. We also need to change enviromentName to the same name as the sandbox.
To be on safe side we could add the tenant property which is the id in the url string between dynnamics.com and sandbox name.
https://businesscentral.dynamics.com/<tenantId>/<sandboxName>
If you try go initialize snapshot you should get this (CTRL+Shift + P, AL: Initialize snapshot debugging, or press F7):
[2023-10-12 13:02:58.05] Initializing a snapshot debugging request on debugging context :5041bba9-6353-4cd9-b5d1-24e6168637ef
[2023-10-12 13:02:58.05] Sending request to https://api.businesscentral.dynamics.com/v2.0/<SandboxName>/snapshotdebugger/attach?debuggingcontext=5041bba9-6353-4cd9-b5d1-24e6168637ef
[2023-10-12 13:02:58.53] The snapshot debugger initialize request for the debugging context '5041bba9-6353-4cd9-b5d1-24e6168637ef' has succeeded.
Check the status of an initialized snapshot by using the 'Show all snapshots' command, or by clicking the snapshot debugger icon in the left corner of the toolbar.
First time you may need to create a link between your account and the tenant by authorizing yourself.
REMEMBER! If when you debug it is important that you have downloaded the same symbols that exists in the target machine or the debugging won’t work. So once you have established connection to sandbox. Choose download all symbols
Once you have verified you have connection you can add userID and session id to whom you would like to connect the snapshot debugger to.
{
"name": "snapshotInitialize: Microsoft production cloud",
"type": "al",
"request": "snapshotInitialize",
"environmentType": "Sandbox",
"environmentName": "<SandboxName>",
"breakOnNext": "WebClient",
"executionContext": "DebugAndProfile",
"userId": "<UserGuidInBC>",
"sessionId": -1
},
To get the userID when connecting to a sandbox you need to open Users in Business Central and “Zoom” by opening the page inspection for that user record and copy the “User Security ID”.
You get the session id by opening the “Question mark”/Help, choose “Help & Support”, go down to Report a problem and there you will find “Session ID (server)” which has the id to the user you would like to record/snapshot. Copy that to the sessionId in launch.json.
Now launch the initialize snapshot debugger again. The result should be something like this if you have done it right. After that, do the thing and choose finish snapshot when you are done.
[2023-10-12 13:33:45.48] Initializing a snapshot debugging request on debugging context :77d****-****-****-****-****
[2023-10-12 13:33:45.48] Sending request to https://api.businesscentral.dynamics.com/v2.0/****/snapshotdebugger/attach?debuggingcontext=****-ac67-****-bcef-****f3c&sessionid=31500&userid=****-****-****-****-****
[2023-10-12 13:33:45.92] The snapshot debugger initialize request for the debugging context '****-****-****-****-****' has succeeded.
Check the status of an initialized snapshot by using the 'Show all snapshots' command, or by clicking the snapshot debugger icon in the left corner of the toolbar.
If you get something like this it is because you haven’t filled in the Guid for the user.
[2023-10-12 13:40:24.63] Initializing a snapshot debugging request on debugging context :****-****-****-****-****
[2023-10-12 13:40:24.64] Sending request to https://api.businesscentral.dynamics.com/v2.0/****/snapshotdebugger/attach?debuggingcontext=****-****-****-****&sessionid=31500&userid=user%40company.com
[2023-10-12 13:40:26.31] The request for path /v2.0/EQM/snapshotdebugger/attach?debuggingcontext=****-6fbf-****-****-****&sessionid=31500&userid=user%40company.com failed with code BadRequest. Reason: The snapshot debugging session could not be started. The user GUID 'user@company.com' is not valid.