ServiceNow - Getting all records

自闭症网瘾萝莉.ら 提交于 2019-12-11 12:09:12

问题


In ServiceNow, I am able to get only a maximum of 250 records in a SOAP request. How to get all the records?

Web Reference Url = https://*****.service-now.com/rm_story.do?WSDL

Code:

            var url = "https://*****.service-now.com/rm_story.do?SOAP";
            var userName = *****;
            var password = *****;

            var proxy = new ServiceNow_rm_story
            {
                Url = url,
                Credentials = new NetworkCredential(userName, password)
            };

            try
            {
                var objRecord = new Namespace.WebReference.getRecords
                {
                    // filters..
                };

                var recordResults = proxy.getRecords(objRecord);
            }
            catch (Exception ex)
            {

            }

In recordResults, I am getting only 250 records. How to get all the records ?


回答1:


Also see this stack overflow answer which provides info. Get ServiceNow Records Powershell - More than 250

Note that returning a large number of records can affect performance of the response and it may be more efficient to process your query in batches using offsets (i.e., get 1-100, then 101-200, ...). This can be achieved by using a sort order and offset. The ServiceNow REST Table API actually returns link headers from Get requests providing you links for the first, next and last set of records making it easy to know the url to query the next batch of records.

See: http://wiki.servicenow.com/index.php?title=Table_API#Methods and look under 'Response Header'.




回答2:


Have u tried to pass/override __limit parameter?

Google / wiki / Users manual / Release notes are always helpful




回答3:


In your code snippet in line where it says //filter you should define __limit (and potentially __first_row and __last_row as explained in the example bellow)

int Skip = 0;
int Take = 250;
while (true)
{
     using (var soapClient = new ServiceNowLocations.ServiceNow_cmn_location())
     {
          var cred = new System.Net.NetworkCredential(_user, _pass);
          soapClient.Credentials = cred;
          soapClient.Url = _apiUrl + "cmn_location.do?SOAP";

          var getParams = new ServiceNowLocations.getRecords() 
          { 
                __first_row = Skip.ToString(), 
                __last_row = (Skip + Take).ToString(), 
                __limit = Take.ToString() 
          };

          var records = soapClient.getRecords(getParams);

          if (records != null)
          {
               if (records.Count() == 0)
               {
                   break;
               }  

               Skip += records.Count();                      

               if (records.Count() != Take)
               {
                    // last batch or everything in first batch
                    break;
               }                
          }
          else
          {
               // service now web service endpoint not configured correctly
               break;
          }
     }
}


来源:https://stackoverflow.com/questions/30116683/servicenow-getting-all-records

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!