Rest API - BR not capturing body

Shivani Malhan
Tera Contributor

Hi All,

I have a requirement where I need to send an update back to third party when worknotes are changed. I created the business rule with condition "current.work_notes.changes()"

BR is getting triggered but when I am capturing the fields in body nothing is getting captured and it is not going inside try. Directly going in catch so not sending any data. Below is the BR. I captured work notes in var notes and getting log: "Notes 26-08-2022 17:26:15 - Shivani Malhan (Work notes)
test7"

Then in var body i am giving the fields which i want to send. and in logs I am getting: "Body [object Object]"

Business Rule:

 

(function executeRule(current, previous /*null when async*/) {
    var sysid = current.sys_id;
    //gs.log('sysid '+sysid);
        var notes = current.work_notes.getJournalEntry(1);
    gs.log('Notes '+notes);   


var body = {

"number": current.number.toString(),
"state":current.getDisplayValue('state'),
"work_notes":notes,
};
    gs.log('Body '+body);

  try { 
 var r = new sn_ws.RESTMessageV2('xyz', 'Default PUT');
    r.setRequestBody(JSON.stringify(body));

 var response = r.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();

 


gs.log('response'+ responseBody);
gs.log("status1234"+ httpStatus);
gs.log('Body'+ r.getRequestBody());
}
catch(ex) {
 var message = ex.message;
    gs.log('fail');
}

})(current, previous);

Need help!!

Thanks,
Shivani

1 ACCEPTED SOLUTION

Are you sure above is the complete code snippet that you are using? 

because in the exception it says "response" is not defined. but actually we defined var response

if you are using other line of coding make sure you define the variable before using it. 


Thanks & Regards,
Vasanth

View solution in original post

6 REPLIES 6

Thank you so much. Issue resolved. There was an error in BR. Instead of response in var, I was using responsew (typo error)

resolved the issue

Thanks,
Shivani

Please close this thread by marking an answer correct 


Thanks & Regards,
Vasanth