Call rest message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2017 04:30 AM
Dear Team,
I have a requirement to call Rest message Post Method from client script.
can any on please help me
Thanks in Adv
- Labels:
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2017 04:57 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2017 04:59 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2017 05:08 AM
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);
}