Send data in chunks using Scripted REST API

SanjivMeher
Kilo Patron
Kilo Patron

Hi All,

We are trying to send Application Data to another external system using REST API. But I keep getting this error if I also send the Description field along with other fields. The reason could be because the description could be huge. Is there a way that we can send data in chunks. So the external system just trigger the web service, but receive data in 4 - 5 chunks?

{
  "error": {
    "detail": "Array object has exceeded maximum permitted size of 268435456",
    "message": "Script Evaluation Exception"
  },
  "status": "failure"
}

Please mark this response as correct or helpful if it assisted you with your question.
3 REPLIES 3

SanjivMeher
Kilo Patron
Kilo Patron

Anyone?


Please mark this response as correct or helpful if it assisted you with your question.

Shishir Srivast
Mega Sage

Considering 1 Byte as 1 Character, can we think something like below to split the string and call the Rest Message to trigger the method until it process all the text in chunks. Just a thought.

 

	var descriptionText = current.description;
	var descriptionTextLength = descriptionText.length;
	var maxlength = 268435455;
	var minlength = 0;
	do{
		try { 
			var description = descriptionText.slice(minlength, maxlength);
			var r = new sn_ws.RESTMessageV2('2ndSNOWInstance', 'Post Message');
			r.setStringParameterNoEscape('short_description', description);

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

			description = '';
			minlength = maxlength;
			maxlength = parseInt(maxlength) + 268435455;
			descriptionTextLength = parseInt(descriptionTextLength) - parseInt(maxlength);
		}
		catch(ex) {
			var message = ex.getMessage();
		}
	} while(descriptionTextLength <= 0);

SanjivMeher
Kilo Patron
Kilo Patron

The problem is the external system is going to call the ServiceNow REST API. And they will do just one call, and they should receive all the data. 

Now when they are calling our webservice, they get this size error message. The size is the size of the whole response from ServiceNow. And we want to send everything and dont want to truncate the data.

What would be the best solution? Or is there a better way to integrate in such scenario?


Please mark this response as correct or helpful if it assisted you with your question.