Incoming REST Response: handling large response with pagination

 example looping through each page of the request data set

var r = new sn_ws.RESTMessageV2('<rest_msg_name>'); var header = r.getRequestHeader("Accept"); var authorization = r.getRequestHeader("Authorization"); r.setStringParameterNoEscape("aParam", aParam); r.setQueryParameter('aParam2', aParam); r.setQueryParameter('per_page', '20'); r.setQueryParameter('page', '1'); var resp = r.execute(); var responseBody = resp.haveError() ? resp.getErrorMessage() : resp.getBody(); var httpStatus = resp.getStatusCode(); var objC = JSON.parse(responseBody); var cPagiNation = objC.pagination.pages; for (var cP = 1; cP <= cPagiNation; cP++) { var r2 = new sn_ws.RESTMessageV2(restName, '<rest_msg_name>'); var header = r2.getRequestHeader("Accept"); var authorization = r2.getRequestHeader("Authorization"); r2.setStringParameterNoEscape("aParam3", aParam3); r2.setQueryParameter('page', cP); var resp2 = r2.execute(); var responseBody2 = resp2.haveError() ? resp2.getErrorMessage() : resp2.getBody(); var httpStatus2 = resp2.getStatusCode(); ... }



see also
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0727636
 
 

https://developer.servicenow.com/dev.do#!/learn/courses/paris/app_store_learnv2_rest_paris_rest_integrations/app_store_learnv2_rest_paris_data_stream_actions/app_store_learnv2_rest_paris_request_pagination_setup_step


 

Comments

Post a Comment

Popular posts from this blog

GlideRecord setValue

URL link in addInfoMessage