【问题标题】:ServiceNow - Getting all recordsServiceNow - 获取所有记录
【发布时间】:2015-05-08 05:52:58
【问题描述】:

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 条记录。如何获取所有记录?

【问题讨论】:

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


    【解决方案1】:

    另请参阅提供信息的堆栈溢出答案。 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 并在“响应标头”下查看。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • var url = "https://*****.service-now.com/rm_story.do?__limit=700&SOAP"; 这是正确的方法吗?添加限制?如果没有,如何在SOAP请求中添加limit?谢谢。
      • 参数必须在请求体中传递,例如: schemas.xmlsoap.org/soap/envelope" xmlns:inc="service-now.com/incident">
        <__encoded_query>state=7<__limit>300
        查看完整的 HTTP 请求示例: gist.github.com/bryanbarnard/fd17525321e0cc64e4f4
      【解决方案3】:

      在你的代码 sn-p 中它说 //filter 你应该定义 __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;
                }
           }
      }
      

      【讨论】:

        【解决方案4】:

        我创建了一个库,可以更轻松地处理与 ServiceNow Rest API 的交互 https://emersonbottero.github.io/ServiceNow.Core/

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-12-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-05-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多