Need to send two rest post messages with one UI action

srinidhi
Tera Guru

Hello Team,

 

Am trying to use two rest messages (post) in one UI action, but only first rest message is getting triggered.

Please help me with any suggestions.

Below is the code.

 

(function executeRule(current, previous /*null when async*/ ) {
   
  var sixDigitRandomisedPin = (Math.floor(100000 + Math.random() * 900000)).toString();
 
sm = new sn_ws.RESTMessageV2('abc, 'xyz');
 
      var requestBody = {
        "firstName": current.parent.u_requested_for_tc.first_name.getDisplayValue(),
        "middleName": "string",
        "lastName": current.parent.u_requested_for_tc.last_name.getDisplayValue(),
        "pin": sixDigitRandomisedPin,
    };
    current.u_pin = sixDigitRandomisedPin;
    current.update();
    sm.setRequestHeader('Content-Type', 'application/json');
    sm.setRequestBody(JSON.stringify(requestBody));
    var response = sm.execute();
    var httpStatus = response.getStatusCode();
    gs.addInfoMessage('Response Status: ' + httpStatus);
    gs.addInfoMessage(JSON.stringify(response.getBody()));
    gs.addInfoMessage(name);
 
sm1 = new sn_ws.RESTMessageV2(abc1', 'xyz1');
var requestBody1 = {
"machineAccessNumber": data,
"locationId": current.parent.u_requested_for_tc.location.getDisplayValue(),
"clientTicketNumber": current.number,
};
//current.update();
sm1.setRequestHeader('Content-Type', 'application/json');
    sm1.setRequestBody(JSON.stringify(requestBody));
    var responses = sm1.execute();
    var httpStatuss = responses.getStatusCode();
    gs.addInfoMessage('Response Status: ' + httpStatuss);
    gs.addInfoMessage(JSON.stringify(responses.getBody()));
    gs.addInfoMessage(name);
 
})(current, previous);

 

Thanks.

10 REPLIES 10

Please put proper quotes 'abc1'

sm1 = new sn_ws.RESTMessageV2('abc1', 'xyz1');

Yes yes done that. still same

Did you try to execute Test Run under Rest messages?

Is it working?

Also, please try to remove current.update() and check

srinidhi
Tera Guru

After running the test for rest message, i got 400 error stating 

 

{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"","errors":{"ProductId":["ProductId missing or invalid."],"LocationId":["LocationId missing or invalid."]}}

pls check and correct from where data value is coming from
 
var requestBody1 = {
"machineAccessNumber": data,
"locationId": current.parent.u_requested_for_tc.location.getDisplayValue(),
"clientTicketNumber": current.number,
};
Also,
Share sample request body that you tried while executing test run