The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How can i call REST API (3rd party) from my UI page in client script or Jelly script.

randeepnath
Mega Contributor

Actually I have a dialogue window (pop up) and have a drop down in that window. I want to update this combo-box (drop down) with the data coming from REST API.

Please help me to achieve this.

7 REPLIES 7

tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi Randeep,



Could you use the approach here


Sending data from SN to an Identity Management Platform via SOAP


but instead of calling SOAPmessage()


call RESTMessageV2


RESTMessageV2



Best Regards



Tony


randeepnath
Mega Contributor

Hi Tony,



Can i call this in client side script ? the following code is correct ? I want to load this data into a combo box while we are calling the dialogue window first time ,,



$j(document).ready(function () {


// Call RESTAPI here ?



  });


it seems you are using jquery in your page so you can use ajax method of jquery to make rest calls.


http://api.jquery.com/jquery.ajax/


alternativly you can use $http method of angular JS. but since you have jquery Out of box in servicenow go for jquery if it is small page.


AngularJS



i hope this helps.


Hi Randeep,



You can use jquery in client scripts. following code is an example GET REST request . for additional details about ajax request http://api.jquery.com/jquery.ajax



$j(function() {


             


                              var request = $j.ajax({


                                      type: "GET",


                                      url: url1, // REST endpoint. replace url1 with REST Endpoint


                                    // data : {},//json data. use data and contentType attributes for POST requests.


                                    // contentType: "application/json",


                                      dataType: "json",


                                      /*xhrFields: {


                                              'withCredentials': true //Tell browser to provide credentials


                                      },


                                      crossDomain: true,// this is for cross domain requests*/


                                      success: function (data,status,jqXHR){


                                              console.log("status:"+status);


                                      },


                                      error: function (jqXHR,status){


                                              console.log("failed: "+jqXHR+"\nstatus:"+status);


                                      },


                                     


                                      complete : function(jqXHR,status)


                                      {


                                              console.log("status: "+status);


                                             


                                      }


                                     


                              });


                             


              });