Hello @booher04 

 

It's because you are calling the rest message function outside the loop. It's having only first initialized value, that's why working for only one. 

 

Please use below 👇 script - 

 

var mrvs = current.variables.access_request_detail;
var rowCount = mrvs.getRowCount();

// Function to send REST request
function sendRestRequest(dest, sourceIp, destIp) {
try {
var r = new sn_ws.RESTMessageV2('AlgoSec', 'AlgoSec POST');
r.setRequestHeader('Cookie', current.variables.sessionid.toString());

r.setStringParameterNoEscape('service', dest);
r.setStringParameterNoEscape('application', "any");
r.setStringParameterNoEscape('source', sourceIp);
r.setStringParameterNoEscape('destination', destIp);

var response = r.execute();
gs.info('Request body: ' + r.getRequestBody());

return response.getBody();
} catch (ex) {
gs.error('REST request failed: ' + ex.message);
return null;
}
}

// Loop through the MRVS contents
var responseBody = '';
for (var i = 0; i < rowCount; i++) {
var row = mrvs.getRow(i);
var dest = row.destination_tcp_port;
var sourceIp = row.source_ip_address_es;
var destIp = row.destination_ip_address_es;

responseBody = sendRestRequest(dest, sourceIp, destIp);
}

// Store the last response in the variable
current.variables.xml_response = responseBody;

 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

View solution in original post