How do I Load an XML/Jelly Script in a System Widget?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2025 02:59 PM - edited 05-26-2025 07:31 PM
I'm trying to load an XML script via a system widget - exactly as Dynamic Content blocks do - but my code is erroring out in the end on everything I try. This is tested via trying to add the widget to a dashboard. During my testing, my sample XML script loads the widget preview and can be added onto the dashboard (but fails to get added if it has a g:evaluate tag) but causes the tab to crash on all future loads, requiring you to load into a tab that lacks the widget to get into the dashboard. (The error on reloading the dashboard tab is 'The processing instruction target matching "[xX][mM][lL]" is not allowed.)
UPDATE: I found out that it's the <g:evaluate> tag I had in my XML script that was causing the dashboard to fail to add the widget to it when clicking the "Add" button. Having g:evaluate tags not working is obviously not an option, but at least it's a little more information on the root cause for the cannot-add-widget issue. They cause the failure even when commented out. Also, even without g:evaluate, I still get the [xX][mM][lL] error on page reload. What is causing this behavior? Is GlideJellyRunner.run simply not capable of handling this scenario for solutions built by us, the customers? If not, what tools have been put at our disposal for achieving this goal? I find the documentation surrounding this to be EXTREMELY light, sadly, which also doesn't help. (My end goal is to make the sys_widget load a selection of UI macros AND the ad-hoc XML script. I'd prefer to only load the UI macros once, while the dashboard is initializing, but again the documentation for achieving such a feat is nonexistent, nor have I found any undocumented way of doing so. All these UI macros do are define some client-side objects, akin to loading a library.)
Please advise how I need to adjust the code to properly load the XML script. I've included the code and a mockup of the sys_widgets and the x_373174_dcm_dynamic_content record to aid in replicating the issue. Thanks!
sys_widget
function sections() {
var widgets = {};
var content = new GlideRecord('x_373174_dcm_dynamic_content');
content.query();
while (content.next()) {
widgets[content.name] = {};
widgets[content.name].sys_id = content.getUniqueValue();
widgets[content.name].xml = content.xml.getXMLValue();
}
return widgets;
}
function render() {
var jr = new GlideJellyRunner();
renderer.getRenderProperties().setDeferInlineScripts(false);
jr.setRenderProperties(renderer.getRenderProperties());
jr.setTwoPhase(true);
return jr.run(renderer.getPreferences().get("xml"));
}
function getEditLink() {
if (!gs.hasRole('content_admin')) {
return '';
}
return "x_373174_dcm_dynamic_content.do?sys_id=" + renderer.getPreferences().get("sys_id");
}
x_373174_dcm_dynamic_content
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<!-- Stop Here if Previewing for Crash Prevention -->
<j:if test="${RP.isPreview()}">
<p>No preview available.</p> <!-- works -->
<j:break/>
</j:if>
<!-- If I add a g : evaluate tag here, the widget cannot be added to the dashboard... -->
<!-- Display Sample Paragraph -->
<p>This is a sample paragraph2.</p> <!-- works -->
</j:jelly>
To test with the update set:
1. Load the update set
2. Load a dashboard
3. Open the "Add widget" UI
4. Choose the "Dynamic Content Block Mockups" category
5. Select the "Sample Paragraph" widget
6. Observe the preview and/or add the widget to the dashboard (preview loads, widget adds, reload page gets [xX][mM][lL] error)
7. Tweak the "Dynamic Content Block Mockups" sys_widgets and try again