Debugging UI Builder Page Scripts

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2022 07:09 AM
I'm actually in a Tokyo PDI, I am unable to quickly see if this issue also exists in San Diego, I'm assuming this is consistent
So I've been having a play with UI builder and after some considerable time banging my head against an issue I've realised that thrown errors in client side code aren't being presented in the browser console.
console.log works however console.warn, console.error, throw or just uncaught errors aren't presented at all.
I'm pretty much new to React as well, I reckon this is probably something to do with Error Boundries?
So the only way I can see to debug code is to wrap the entire code block I want to debug in a try and in the catch just console log it...
try{ /* code to debug*/ } catch(err){console.log("ERROR:", err);}
Am I missing some ServiceNow/UI Builder/Experience toggle? Is there some browser config I'm missing? Or some React specific coding pattern I need to follow? Or is this really how to debug?
- Labels:
-
UI Builder : Next Experience
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2022 11:49 PM
Hi John,
Probably not the answer you are looking for, but if you really want to debug, i.e. use breakpoints, view the stack and experiment in the console while the script is executing, I'd recommend trying one of the options bellow. I'm not sure how to make client-side errors appear in the console automatically, though.
1. Place debugger; before the line you wish the debugging to start, e.g.
/**
* @param {params} params
* @param {api} params.api
* @param {any} params.imports
*/
function evaluateProperty({api}) {
debugger;
return `Status is ${api.data.case.result.state.value} (${api.data.case.result.state.displayValue})`;
}
Then load the page with the developer console open and the code breaks execution at this line.
2. If you don't want to modify your code, find a snippet which is unlikely to appear in other scripts and copy it. In my case, that could be return `Status is ${api.data.case.result.state.value}
Load the page, let the script execute first (so it's evaluated by the browser) and then press Ctrl+Shift+F in the developer console (Chrome). Paste the code snippet , hit enter and then click on the highlighted result, which will bring you to the evaluated source where you can place breakpoints. Of course, then you need to execute the script once again (or reload the page).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 12:37 AM
Thanks Martin, it isn't quite what I'm looking for but that may indeed reduce the pain somewhat.