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

Vasantharajan N
Giga Sage
Giga Sage

GlideAjax with getXMLAnswer() method will only return the exact answer you need. 

 

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

 

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

}

 


Thanks & Regards,
Vasanth

its working fine but in u_comment iam getting "null"

Could you please confirm whether you are getting the alert popup with correct value.

What type of field u_comment?


Thanks & Regards,
Vasanth

iam getting alert pop up null ...and in u_comment also null..u_comment is multi line text variable on catalog item