- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 09:39 AM - edited 05-20-2025 09:45 AM
I'm trying to figure this out and have done some test prints to see what's going on at various stages and parts of a widget I'm editing. The server-side sets a value "shortDesc" which is used to print the title of the KB article in the HTML (no idea what the :: preceding the value is though... what is that about?). The problem that it gets the shortDesc value from the knowledgeRecord object which, if I set to a variable to keep it for a sec and then print it in HTML to confirm its value, is blank.
So where is shortDesc getting it's value from? This line is the only one in the Server side that references this value:
Also, the "stuff" value is only set on this one line, immediately after the other which shows that the value set is empty, even though somehow it's not empty when HTML prints it. It's dark magic, surely.
Also, what is the double colon doing there? What does that signify? If I remove it, it works exactly the same.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 08:47 AM
Hello @jeremyduffy ,
You need to use the "Log to console: $scope.data" option.
It won't show your code. It will show you the properties of the "data" object so that you can verify if they have the expected values.
But you need to do that while right-clicking on your widget on an actual portal page as shown in my screen shot. It seems you right-clicked on the widget editor (which is a widget itself).
The reason why your "stuff" object appears to have empty properties is that you have assigned the "knowledgeRecord" object to it, which is a GlideRecord Java object and not a native JavaScript object. So "knowledgeRecord.short_description" is not a string but a GlideElement Java object, which cannot be "stringified" to JSON (which is what happens when you add {{data.stuff}} to the HTML template) and that's why you just see the "empty object" / {}.
On the other hand, "data.shortDesc" has a value that AngularJS can work with, because your code casts it to an actual JavaScript string by adding the "".
knowledgeRecord.short_description.getDisplayValue() + "";
You still have not clarified what's the actual issue you are trying to debug. You mention that the short description / title "works fine", so what is not working?
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 09:20 AM - edited 05-22-2025 09:22 AM
So the immediate problem is solved, but $scope.data doesn't seem to have any of the information about the variables set here:
var kbViewModel = new global.KBViewModel();
var kbPortal = new KBPortalService();
var knowledgeRecord = kbViewModel.knowledgeRecord;
I want to be able to view that entire value all at once (hence why I was trying to print it out to HTML to view it. Is there a way to do this? The question is complete, but if you can give me a hint, that would be amazing.
I just need to know how to view the value of variables and objects at certain points in the script like I would if I were debugging HTML/JS. I tried console.log, but the variable is some kind of fancy html object that doesn't seem to have any actual data so that doesn't work. I tried setting the variable on server side then using console.log client side, but that has the same object that I see if I print it in HTML.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 09:42 AM
Hello @jeremyduffy ,
Please update your Widget's server script as follows:
...
data.shortDesc = knowledgeRecord.short_description.getDisplayValue() + "";
// add this
data.stuff = {};
for (var field in knowledgeRecord) {
data.stuff[field] = knowledgeRecord.getValue(field);
}
...
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 10:51 AM
Awesome! That's exactly what I needed 🙂