REST "Uncaught ReferenceError: sn_ws is not defined"

xiaix
Tera Guru

find_real_file.png

function testMe()

{

      var r = new sn_ws.RESTMessageV2('test', 'get');

      console.debug("r: " + r);

     

      var response = r.execute();

      console.debug("response: " + response);

     

      var responseBody = response.getBody();

      console.debug("responseBody: " + responseBody);

     

      var httpStatus = response.getStatusCode();

      console.debug("httpStatus: " + httpStatus);

}

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi David,



You may find the below thread helpful.


Scope Question: Integration APIs - sn_ws


View solution in original post

10 REPLIES 10

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi David,



You may find the below thread helpful.


Scope Question: Integration APIs - sn_ws


Chuck Tomasi
Tera Patron

Hi David,



Can you do a test from scripts background and see if it runs all by itself?   Just copy and paste the code above and call your testMe() function.


Chuck Tomasi
Tera Patron

Just to verify... where is this code being called from? It's server side code and should not be in a client script.


xiaix
Tera Guru

I'm not-so-bright today.   I was doing this in a UI Page Client Script.   It needs to be server side.   doh!!



This is what worked:   (UI Page Client Script)



function testMe()


{


      var gaj = new GlideAjax('REST_API_CALL');


      gaj.addParam('sysparm_name', 'getData');


      gaj.getXMLWait();


      var answer = gaj.getAnswer();


      console.debug("answer: " + answer);


}




Script Include:



var REST_API_CALL = Class.create();




REST_API_CALL.prototype = Object.extendsObject(AbstractAjaxProcessor, {




      getData: function()


      {    


              var r = new sn_ws.RESTMessageV2('test', 'get');


              var response = r.execute();


              var responseBody = response.getBody();


              return responseBody;


      }


});