new SPGlideAjax($http)
A simplified version of GlideAJAX for use within the Service Portal.
This specifically implements getAnswer and getXMLAnswer with some modernization for Promise support through Angular's $http service.
Parameters:
Name | Type | Description |
---|---|---|
$http |
$http |
- Source:
Example
// Script Include var Example = Class.create(); Example.prototype = Object.extendsObject(AbstractAjaxProcessor, { "type": "Example", "functionA": function() { return this.getParameter("a"); } }); // Client Script function _controller($scope, SPGlideAjax) { var ga = new SPGlideAjax("Example"); ga.addParam("sysparm_name", "functionA"); ga.addParam("a", 9); // (This will print "9" as a warning to the browser's console) ga.getXMLAnswer(console.warn); }
Members
-
<private> generalOptions :Object
-
General options to use with all $HTTP calls
Type:
- Object
- Source:
-
<private> regexSpace :RegExp
-
Static space reference for quick replacement.
Type:
- RegExp
- Source:
Methods
-
addParam(field, value)
-
Sets a parameter for a pending AJAX request.
Parameters:
Name Type Description field
String The name of the field to be passed.
value
String The value to be passed for that field.
- Source:
-
getAnswer(callback)
-
Uses the parameters object to handle processing.
If the sysparm_name property is missing, a warning is sent to the console for developer awareness.
Parameters:
Name Type Description callback
function Takes callback(answer, error) and resolves appropriately the same as the returned promise.
- Source:
Returns:
The promise resolves with the answer XML element on success or an Error object on failure.
- Type
- Promise
-
getXMLAnswer(callback)
-
Get the answer property from the returned XML.
Parameters:
Name Type Description callback
function Takes callback(answer, error) and resolves appropriately the same as the returned promise.
- Source:
Returns:
Resolves on success with the answer string and on failure throws to the catch chain.
- Type
- Promise
-
serializeToForm(data)
-
Service-Now's GlideAjax works with form data strings instead of JSON, so this is used to convert the parameters to the appropriate format.
Parameters:
Name Type Description data
Object The object to parse into form data. The values off the object should be easily represented as strings or issues may occur.
- Source:
Returns:
Form data string of the data in the passed object
- Type
- String