I am trying to get data from service now table in angular JS using Glide Ajax method.But I always get null in angular when i try to print the data obtained from backend .Please help...

dddddddddddddd
Kilo Explorer

I am trying to get data from service now table in angular JS using Glide Ajax method.

But I always get null in angular when i try to print the data obtained from backend .

This is my function from angular

  $scope.getRecords = function(){

  var ga = new GlideAjax('TodoAppPersistence');  

//ga.setScope('global'); // NS > change it to your scope

  ga.addParam('sysparm_name', 'getList');  

  ga.getJSON(function(response){  

         

  $scope.todos = response;
  console.log($scope.todos );

});  

  };

This is my script include

var TodoAppPersistence = Class.create();

TodoAppPersistence.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getList: function() {

var todos = new GlideRecord('Incident');

todos.query();

var list = [];

while (todos.next()) {

list.push(todos.short_description + '');

}

return new global.JSON().encodeArray(list);

},

      type: 'TodoAppPersistence'

});

I have tried this in global scope as well as local scope, none is working

Even tried to put gs.log , but not even getting any log , as if it is not able to locate my script include function

I have even configured the sn.service file for Glide Ajax.

Please help...

2 REPLIES 2

Rushit Patel2
Tera Guru

blog post suggested by deepak will definitely help you. in your angular function side you are using ga.getJSON() function. i dont think it supports it OOB. you must extend OOB glideajax to have support of JSON.



there is post on developer site that does it.



you need to include below module in your app



angular.module('sn.glideAjax', []); angular.module('sn.glideAjax').service('GlideAjax', function($rootScope) { var glideAjax = window.GlideAjax; glideAjax.prototype.getJSON = function(callback) { this.getXMLAnswer(function(answer) { var answerJSON = JSON.parse(answer); callback(answerJSON); $rootScope.$apply(); }); };   return glideAjax; });


There is nice tutorial on developer site..check it out.


ServiceNow Developers



(please mark helpful/correct based on impact)