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!/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 )



Post a Comment

Popular posts from this blog

URL link in addInfoMessage

var ga=new GlideAjax('gld_HR_ajax'); ga.addParam('sysparm_name', 'checkEmployeeNumber_hrProfile'); ga.addParam('sysparm_hrprofilenumber', g_form.getValue('number')); ga.addParam('sysparm_employeenumber', newValue); ga.getXMLAnswer(function(answer) { if (answer!='undefined' && answer!=''){ var navURL="<a style='text-decoration:underline;color:blue'" + answer + ">" + answer + "</a><img width='3' src='images/s.gif'/>"; var sMsg='The employee number entered already exists on another HR Profile ' + navURL; //alert(sMsg); g_form.showErrorBox('employee_number', 'error - please check'); g_form.addInfoMessage(sMsg); } });

GlideRecord setValue

setValue(String name, Object value) Sets the specified field to the specified value. Normally a script would do a direct assignment, for example,  gr.category = value . However, if in a script the element name is a variable, then  gr.setValue(elementName, value)  can be used. When setting a value, ensure the data type of the field matches the data type of the value you enter. This method cannot be used on journal fields. If the value parameter is null, the record is not updated, and an error is not thrown!/api_doc?v=madrid&id=r_GlideRecord-setValue_String_Object