限制NetSuite中返回的发票对象数量

时间:2016-06-29 20:39:44

标签: c# web-services netsuite invoice

我正在与客户的NetSuite帐户进行集成,其中包括提取发票数据以创建“第一个销售日期”(创建第一个发票)和“上次销售日期”(创建最新发票)。我的问题涉及限制响应中返回的发票数量,因为他们的系统中目前有大约265,000张发票记录 - 其中数百个可以属于一个客户记录。有没有办法只为每个客户请求两张必要的发票记录?

这是我目前在C#中的代码:

int invoiceCount = 0;

private void searchInvoices()
{
    // This operation requires a valid session 
    this.login(true);

    TransactionSearch transactionsSearch = new TransactionSearch();
    TransactionSearchBasic transactionSearchBasic = new TransactionSearchBasic();

    transactionSearchBasic.type = new SearchEnumMultiSelectField();
    transactionSearchBasic.type.@operator = SearchEnumMultiSelectFieldOperator.anyOf;
    transactionSearchBasic.type.operatorSpecified = true;
    transactionSearchBasic.type.searchValue = new string[] { "_invoice" };

    transactionsSearch.basic = transactionSearchBasic;

    SearchResult transactionResponse = _service.search(transactionsSearch);

    Invoice[] invoices = new Invoice[transactionResponse.totalRecords];

    if (transactionResponse.status.isSuccess)
    {
        if (transactionResponse.totalRecords > 0)
        {
            for (int i = 1; i <= transactionResponse.totalPages; i++)
            {
                invoices = processTransactionSearchResponse(transactionResponse, invoices);

                if (transactionResponse.pageIndex < transactionResponse.totalPages)
                {
                    this.setPreferences();
                    this.login(true);
                    transactionResponse = _service.searchMoreWithId(transactionResponse.searchId, i + 1);

                }
            }
        }
        else
        {
            _out.info("\nNothing found.");
        }
    }
}

private Invoice[] processTransactionSearchResponse(SearchResult transResult, Invoice[] invoices)
{
    Record[] transactionRecords = transResult.recordList;
    Invoice invoice = new Invoice();

    foreach (Record rec in transactionRecords)
    {
        invoice = (Invoice)rec;
        invoices[invoiceCount] = invoice;

        invoiceCount++;
    }

    return invoices;
}

2 个答案:

答案 0 :(得分:0)

totalRecords的长度是265k吗?

如果是这样,那么你真的不能回复我的X记录,但你可以做一些像按日期过滤的事情。

答案 1 :(得分:0)

首先与所有客户创建一个搜索,然后制作一个foreach来获取发票或使用这样的trandate:

SearchDateField date = new SearchDateField();
date.@operator = SearchDateFieldOperator.before;
date.operatorSpecified = true;
date.searchValue = DateTime.Now.AddDays