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

yes 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 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'
});

@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

thank you @Vasantharajan N  its working fine. Thank you so much for your help

Basheer
Mega Sage

As you have used getXMLAnswer you don't need to use 

var answer = response.responseXML.documentElement.getAttribute("answer"); //Comment this line

 

Remove '' for alert('answer') and alert('reqbody')

 

function getResponse(answer){
alert(answer);
var reqbody = JSON.stringify(answer);
alert(reqbody);
g_form.setValue('u_comment',reqbody);

}

 

 

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

its working fine but in u_comment iam getting "null"