Unable to construct URL with sysparm_query parameter in Angular Controller

tt-jtw
Kilo Expert

I was trying to use Angular in my ServiceNow instance -- starting with the example in this thread.

 

Getting Started with AngularJS in ServiceNow

 

I wasn't able to construct the URL proper to bring in only the active users.   I tried:

 

'/sys_user_list.do?JSONv2&sysparm_query=active=true'

'/sys_user_list.do?JSONv2&sysparm_action=getRecords&sysparm_query=active=true'

 

As in:

function UserController($scope, $http) {

          $http.get('/sys_user_list.do?JSONv2&sysparm_action=getRecords&sysparm_query=active=true')

              .success(function(data, status, headers, config) {

                  $scope.users = data.records;

              });

      }

 

I always seem to get the full list of users back.

2 REPLIES 2

Jay_Ford
Kilo Guru

If you are on a release prior to dublin you have to use JSON instead of JSONv2. If you're dubliin or higher you can do it one of two ways.



If you keep the script inside the HTML field of the UI page. You have to add the Jelly & like this.



  <script>


      var app = angular.module( 'myApp', [] );


      function UserController($scope, $http) {


          $http.get('/sys_user_list.do?JSONv2$[AMP]sysparm_query=active=true')


              .success(function(data, status, headers, config) {


                  $scope.users = data.records;


              });


      }


  </script>



Or you could move the whole script into the client script area of the UI page and do it like this.



      var app = angular.module( 'myApp', [] );


      function UserController($scope, $http) {


          $http.get('/sys_user_list.do?JSONv2&sysparm_query=active=true')


              .success(function(data, status, headers, config) {


                  $scope.users = data.records;


              });


      }


tt-jtw
Kilo Expert

Worked perfectly.   Thanks!