- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2021 01:07 AM
Hi everyone,
is there a way to call server side code (script include) from a client script in UI Builder? The script include is client callable and I tried to call it via GlideAjax, but no success.
Can anyone share some experiences regarding that topic?
Thanks.
Solved! Go to Solution.
- 6,459 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2021 02:21 AM
You can use helpers.snHttp for example to get any information via HTTP request. The corresponding code example could look like
/**
* @param {params} params
* @param {api} params.api
* @param {any} params.event
* @param {any} params.imports
*/
function handler({api, event, helpers, imports}) {
helpers.snHttp(
"/api/now/table/incident/a83820b58f723300e7e16c7827bdeed2",
{
method: "GET"
}
).then(({ response: { result } }) => {
debugger;
console.log(`number=${result.number}; short_description="${result.short_description}"`);
});
}
or, using async/await which simplifies working with Promises, like the following
/**
* @param {params} params
* @param {api} params.api
* @param {any} params.event
* @param {any} params.imports
*/
async function handler({api, event, helpers, imports}) {
const { response: { result } } = await helpers.snHttp(
"/api/now/table/incident/a83820b58f723300e7e16c7827bdeed2",
{
method: "GET"
}
);
console.log(`number=${result.number}; short_description="${result.short_description}"`);
}
So you can create simply Scripted REST API and call it for loading required information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2021 02:21 AM
You can use helpers.snHttp for example to get any information via HTTP request. The corresponding code example could look like
/**
* @param {params} params
* @param {api} params.api
* @param {any} params.event
* @param {any} params.imports
*/
function handler({api, event, helpers, imports}) {
helpers.snHttp(
"/api/now/table/incident/a83820b58f723300e7e16c7827bdeed2",
{
method: "GET"
}
).then(({ response: { result } }) => {
debugger;
console.log(`number=${result.number}; short_description="${result.short_description}"`);
});
}
or, using async/await which simplifies working with Promises, like the following
/**
* @param {params} params
* @param {api} params.api
* @param {any} params.event
* @param {any} params.imports
*/
async function handler({api, event, helpers, imports}) {
const { response: { result } } = await helpers.snHttp(
"/api/now/table/incident/a83820b58f723300e7e16c7827bdeed2",
{
method: "GET"
}
);
console.log(`number=${result.number}; short_description="${result.short_description}"`);
}
So you can create simply Scripted REST API and call it for loading required information.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2021 11:02 PM
Hi, you could create a new transform data resource for that. I highly recommend to have a look at some overview of how data resources work https://developer.servicenow.com/blog.do?p=/post/quebec-ui-builder-data-resources/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2021 01:08 AM
Thanks for your answer. Do you have a code example how to call the script include via transform data resource? I tried but no success.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2021 01:12 AM
First you need to have a transform data broker script, in which you have a script field.
function transform(input) {
//put any server side logic here
}
If you need to pass some input parameters you need to specify them within properties field. Just have a look at some OOTB examples. It is just a JSON. If you are updating/creating/deleting some gliderecord than don't forget to check mutates server data checkbox.
You also need to create an ACL for this data resource.
After that you can add that data resource on the page and execute it within the client script:
function handler({api, event, helpers, imports}) {
api.data.id_of_your_data_resource.execute();
}
you can also pass some input parameters into the data resource by passing an object with appropriate key,value pairs.