ServiceNow - 获取所有记录

时间:2015-05-08 05:52:58

标签: c# .net c#-4.0 servicenow

ServiceNow中,我只能在SOAP请求中获得最多 250 记录。如何获取 所有 记录?

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

代码:

            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)
            {

            }

recordResults中,我只获得 250 条记录。如何获得所有记录?

3 个答案:

答案 0 :(得分:2)

另见这个提供信息的堆栈溢出答案。 Get ServiceNow Records Powershell - More than 250

请注意,返回大量记录会影响响应的性能,使用偏移量批量处理查询可能更有效(即获得1-100,然后是101-200,...)。这可以通过使用排序顺序和偏移来实现。 ServiceNow REST Table API实际上从Get请求返回链接头,为您提供第一组,下一组和最后一组记录的链接,以便您轻松了解查询下一批记录的URL。

请参阅:http://wiki.servicenow.com/index.php?title=Table_API#Methods 并查看“响应标题”。

答案 1 :(得分:1)

您是否曾尝试传递/覆盖__limit参数?

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

答案 2 :(得分:0)

在你的//过滤器的代码片段中你应该定义__limit(可能__first_row和__last_row,如下面的例子所示)

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;
          }
     }
}
相关问题