This is a demo of promise like service which allows to make a GlideAjax call directly from the controller function.
The service has a single method called getAnswer
which returns a promise, which is then resolved directly to the answer attribute from the XML response.
The method accepts 3 parameters:
processor
- name of the client callable script includename
- method name you would like to executeparams
- object containing additional parameters
- create an angular provider with the name
spGlideAjax
- paste the content of
spGlideAjaxService.js
into the client script field - associate the angular provider with the widget where you would like to use it
- you can now use it as described within example usage
ℹ️ for more info visit docs
api.controller = function (spGlideAjax) {
/* widget controller */
var c = this;
c.getGlideDateTime = function (ms) {
spGlideAjax
.getAnswer("DateTimeUtils", "msToGlideDateTime", {
sysparm_value: ms,
})
.then(
function (resp) {
console.log(resp);
},
function (error) {
console.error(error);
}
);
};
};