get request body

shabbir9
Tera Contributor

hii

in script include "GetEnclaveData" iam getting the rest message response in responsebody(
(var responseBody = response.getBody();) i need fetch that responsebody and show it on u_comment variable can anyone correct this script where i am doing wrong in below client script i need to fetch script include responsebody onto this client script ..

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;

}
var ga = new GlideAjax('GetEnclaveData');
ga.addParam('sysparm_name','getData');
ga.getXMLAnswer(getResponse);
alert('hello');
function getResponse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('answer');
var reqbody = JSON.stringify(answer);
alert('reqbody');
g_form.setValue('u_comment',reqbody);

1 ACCEPTED SOLUTION

@shabbir9  Please add the return statement in your script include method named getData() to get the response body when you make Ajax call from client script.

 

 

var GetEnclaveData = Class.create();

GetEnclaveData.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getData: function() {
        var restMessage = new sn_ws.RESTMessageV2('`network Access', 'GET network Data By network Name');
        //restMessage.setEndpoint(' https://connectivity-api.netbuz-l.cotp/industrial-networks/networks/');
        restMessage.setHttpMethod('GET');
        var queryParam = gs.getVariable('query_param');
        restMessage.addQueryParameter('parameter_name', queryParam);
        var response = restMessage.execute();
        var responseBody = response.getBody();
        gs.log("check enclave response" + responseBody);
        var httpStatus = response.getStatusCode();
        if (httpStatus == 200) {
            // Store the response body in a variable
            gs.setVariable('response', responseBody);
            return JSON.stringify(responseBody);
            // gs.log("check enclave response"+responseBody);
        }
    },
    type: 'GetEnclaveData'
});

 

 


Thanks & Regards,
Vasanth

View solution in original post

17 REPLIES 17

try reqbody.body.data

or reqbody.data

 

g_form.setValue('u_comment',reqbody.body.data);

or

g_form.setValue('u_comment',reqbody.data);

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

shabbir9
Tera Contributor

g_form.setValue('u_comment',reqbody.body.data);     its not working

 

g_form.setValue('u_comment',reqbody.data);   by using this i am getting Undefined in u_comment

check this script inlclude iam getting response body in script include....sharing script include iam getting response body in json..i have checked in logs response ...kindly check how to send this responsebody onto that u_comment varibale(multi line text) on catalog item

 

var GetEnclaveData = Class.create();

GetEnclaveData.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getData:function(){
var restMessage = new sn_ws.RESTMessageV2('`network Access', 'GET network Data By network Name');;
//restMessage.setEndpoint(' https://connectivity-api.netbuz-l.cotp/industrial-networks/networks/');
restMessage.setHttpMethod('GET');
var queryParam = gs.getVariable('query_param');
restMessage.addQueryParameter('parameter_name', queryParam);
var response = restMessage.execute();
var responseBody = response.getBody();
gs.log("check enclave response"+responseBody);
var httpStatus = response.getStatusCode();
if (httpStatus == 200) {
// Store the response body in a variable
gs.setVariable('response', responseBody);
// gs.log("check enclave response"+responseBody);
}
},
type: 'GetEnclaveData'
});

jaheerhattiwale
Mega Sage
Mega Sage

@shabbir9 You should use getXML function when you are using call back function

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;

}
var ga = new GlideAjax('GetEnclaveData');
ga.addParam('sysparm_name','getData');
ga.getXML(getResponse);
alert('hello');
function getResponse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('answer');
var reqbody = JSON.stringify(answer);
alert('reqbody');
g_form.setValue('u_comment',reqbody);

 

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@shabbir9 Did you try this?

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023