How to get the values from response body in rest web service

Chandu Telu
Tera Guru
Tera Guru

Hi All,

I have business rule,

function onAfter(current, previous) {

try {

var r = new sn_ws.RESTMessageV2('onelogin', 'post');

r.setStringParameter('username',current.user_name);

r.setStringParameter('lastname',current.last_name);

r.setStringParameter('email',current.email);

r.setStringParameter('firstname',current.first_name);

var response = r.execute();

var responseBody = response.getBody();

var httpStatus = response.getStatusCode();

    gs.log(typeof(responseBody)

}

catch(ex) {

var message = ex.getMessage();

}    

}

In logs i am getting the answer is string     but i want an object   please can one help me

Thanks

Chandu

5 REPLIES 5

var responseBody = response.getBody();


this.json = new global.JSON().decode(responseBody);


var id = this.json.data.id;    



If the above property is not returning id value, check with below syntax.



var id = this.json.data[0].id;