Call rest message

pra1
Kilo Contributor

Dear Team,

I have a requirement to call Rest message Post Method from client script.

can any on please help me

Thanks in Adv

3 REPLIES 3

amaradiswamy
Kilo Sage

Hi Prashanth,



You can post the rest related script in Script include and call script include from client script by using glideajax method.



Thanks and regards'


Swamy


haseena ayesha
Kilo Guru

Hi


Nimma,



POST method:


The HTTP POST method adds a new record to the collection. POST expects the content-type header to be application/json, and the content being posted to use the following format:


  • users: {"name":"<the user's name>","age":"<the user's age>"}
  • offices: {"city":"<the office location>","state":"${<the state>}","zip":"<the office's zip code>"}

POST returns the ID of the newly added record in the Response body.


please go through the bellow links:


http://wiki.servicenow.com/index.php?title=Outbound_REST_Web_Service#gsc.tab=0


RESTMessageV2 API - ServiceNow Wiki


Scripting Outbound REST - ServiceNow Wiki


Re: Is there any restriction for using REST message in client script of UI Page?





Thanks & Regards


Haseena.


                                                                                    PS: Hit like, Helpful or Correct depending on the impact of the response


amaradiswamy
Kilo Sage

Example:



Script include:


var addDeviceValidation = Class.create();


addDeviceValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  getValidation:function()


  {


var short = this.getParameter('short');


var des = this.getParameter('des')


  var r = new sn_ws.RESTMessageV2('REST API from 15133', 'post');


r.setStringParameter('description', 'This is REST Incident from 18513 ---Description');//send values from client script dynamically


r.setStringParameter('short_description', short);



//override authentication profile


//authentication type ='basic'/ 'oauth2'


//r.setAuthentication(authentication type, profile name);



var response = r.execute();


var responseBody = response.getBody();


var httpStatus = response.getStatusCode();



  },




      type: 'addDeviceValidation'


});


Client script



function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


          return;


  }


  var ga = new GlideAjax("addDeviceValidation");


  ga.addParam("sysparm_name","getValidation");


  ga.addParam("short",g_form.getValue('variablename'));


  ga.addParam("des ",g_form.getValue('variablename'));


  ga.getXML(ajaxResponse);


}