- 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,461 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
06-02-2021 03:31 AM
Thanks for your reply. Your solution worked as well, but I preferred the solution of Oleg.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 09:58 AM
Can anyone in this thread provide an example POST request? I don't know where I'm going wrong.
function handler({api, event, helpers, imports}) {
helpers.snHttp("/api/hesi/depot_workstation/addScanLog", {
method: "POST",
body: "this is the body",
})
.then(({ response: { result } }) => {
debugger;
console.log(`result from UI: ${result}`);
});
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var gr = new GlideRecord('u_scan_log');
gs.log('request: => ' + JSON.stringify(request.body), "Paul");
gs.log('response: => ' + JSON.stringify(response), "Paul");
gr.initialize();
gr.u_scan = request.body.u_serial;
gr.u_message = request.body.u_message;
gr.insert();
})(request, response);