How to retrieve data with a Script Include in UI Builder?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
I'm really new to UI Builder and have a business requirement that I need help with.
Currently, in the core UI forms for catalog tasks (SCTASK), we have a UI Macro on the form that provides a list of consolidated work notes and user comments for the entire request so none get missed when fulfilling a request. The UI macro calls a script include that gathers the data based on two parameters passed - the SCTASK sysid and the RITM sysid.
I need the same functionality for Service Operations Workspace and I'm stuck on how to create a data resource to call the script include. I assume I can pass parameters to the data resource with a client state parameter or field value from the form controller, I just don't know how to do that in a data resource, or even what kind of data resource since I want to re-use the script include code.
Can someone help me out, please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi,
In UI Builder, you cannot directly call Script Includes like in classic UI. Instead, you should use Data Resources or GlideAjax (via client script).
Recommended Approach (Best Practice):
Use a Script Include + Data Resource (Server Script)
Steps:
- Create a Script Include:
var GetData = Class.create();
GetData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var gr = new GlideRecord('incident');
gr.query();
var result = [];
while (gr.next()) {
result.push({
number: gr.number.toString(),
short_description: gr.short_description.toString()
});
}
return JSON.stringify(result);
}
});
- In UI Builder:
- Add a Data Resource → Server Script
- Call the Script Include
- Bind the Data Resource to your component
Alternate (Client-side):
Use GlideAjax from a Client Script if needed.
Explanation:
UI Builder follows a data-driven architecture where Data Resources act as the bridge between UI and server logic.
Reference:
Hope this helps.
Please mark helpful/correct if it worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Thx to all. Not working with Builder so far due to limitations (like most of the new stuff… mostly the f*cking FLOW BS — loved my workflow 😄), but ok — can’t turn back time 😉
I was NOT aware of the workspace part after the script field in the UI Action for Workspace…!!
That is doing the trick.
So ... UI Action as usual with client and server-side coding via…
// client side checks before ...
...
//serverside
... and workspace part adding the same ... and at the end the action is called witch is only set in the upper script filed.
function onClick() {
var test = g_form.getValue('test');
g_form.clearMessages();
if (!test) {
g_form.addErrorMessage(getMessage('test_msg'));
return false;
}
g_form.setValue('approval', 'rejected');
g_form.submit('my_action_name'); // Action name
}
Works now.
