Skip to main content

ServiceNow 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




(ServiceNow )


 

Comments

Post a Comment

Popular posts from this blog

Get URL Parameter - server side script (portal or classic UI)

Classic UI : var sURL_editparam = gs . action . getGlideURI (). getMap (). get ( ' sysparm_aparameter ' ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); } Portal : var sURL_editparam = $sp . getParameter ( " sysparm_aparameter " ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); }

ServiceNow - script include: build up the results as a JSON object (array) - example 2

function call var sCurrentGroupMembers = new <script_include> (). getGroupMembers ( group_sysid ); gs . print ( 'sCurrentGroupMembers:' + sCurrentGroupMembers ); var oGroupMembers = JSON . parse ( sCurrentGroupMembers ); gs . print ( JSON . stringify ( oGroupMembers . users )); oNewGroupMember = JSON . parse ( group_members ); var oGroupConfig = getGroupDeltas ( oGroupMembers . users , oNewGroupMember ); gs . print ( JSON . stringify ( oGroupConfig . remove )); gs . print ( JSON . stringify ( oGroupConfig . add )) output : *** Script: sCurrentGroupMembers: {"manager":"3b2649efdb0f8c10cc0652f3f39xxxxx", "email":"", "type":"33a2226edb99c340edfc7cbdae96xxxx", "description":"Created for xyz", "users":[{"user":"3b2649efdb0f8c10cc0652f3f396xxxx"},{"user":"856a8f71db3d73041b4ffc45ae96196a"},{"user":"3752771