为什么ExpenseLineRetList返回null(Why ExpenseLineRetList

2019-11-03 02:49发布

我看到了这个链接 ,我注意到我们有同样的问题,他的问题仍然没有答案尚未。

这是个问题。

public class ServiceSel
    {
        public void GetCheqe()
        {
            bool sessionBegun = false;
            bool connectionOpen = false;
            QBSessionManager rp = null;

        try
        {
            rp = new QBSessionManager();
            IMsgSetRequest requestMsgSet = rp.CreateMsgSetRequest("US", 8, 0);
            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
            rp.OpenConnection("Database Path File QuickBooks", "QuickBooks Integration Demo");
            connectionOpen = true;
            rp.BeginSession("", ENOpenMode.omDontCare);
            sessionBegun = true;

            ICheckQuery checkQuery = requestMsgSet.AppendCheckQueryRq();
            IMsgSetResponse msgSetRs = rp.DoRequests(requestMsgSet);
            IResponse response = msgSetRs.ResponseList.GetAt(0);
            ICheckRetList checkRetList = (ICheckRetList)response.Detail;

            if (checkRetList != null)
            {
                for (int i = 0; i < checkRetList.Count; i++)
                {
                        ICheckRet checkRet = checkRetList.GetAt(i);
                        //Bank Account On top 
                        string TxnID = checkRet.TxnID.GetValue().ToString();       //Data correct
                        string TxnNumber = checkRet.TxnNumber.GetValue().ToString();   //Data correct
                        string Account = checkRet.AccountRef.FullName.GetValue();   //Data correct
                        string Amount = checkRet.Amount.GetValue().ToString();   //Data correct

                         if (checkRet.ExpenseLineRetList != null)
                         {
                                 Error checkRet.Expense Show null Data But in quickbooks have many data expense in calendar 

                         }      
                }
            }
        }
        catch (Exception ex)
        {
            //MessageBox.Show(ex.Message, "Error");
        }
        finally
        {
            if (sessionBegun)
            {
                rp.EndSession();
            }
            if (connectionOpen)
            {
                rp.CloseConnection();
            }
        }

    }

为什么ExpenseLineRetList为空?

Answer 1:

检查请求将不包括支票的细节行,除非你在查询中包含它。 通过添加IncludeLineItems设置,您就可以访问到检查的费用或项目列表(支票可以有费用项,项目行,或两者)。 你会想改变包括以下内容:

ICheckQuery checkQuery = requestMsgSet.AppendCheckQueryRq();
checkQuery.IncludeLineItems.SetValue(true);
IMsgSetResponse msgSetRs = rp.DoRequests(requestMsgSet);

我也建议你尝试获得响应的细节,这样可以更好地处理错误前检查响应代码:

IResponse response = msgSetRs.ResponseList.GetAt(0);
if(response.StatusCode != 0)
{
    // There was an error. response.StatusCode has the error number
    // response.StatusMessage has the error description.
}
else
{        
    ICheckRetList checkRetList = (ICheckRetList)response.Detail;
    .
    .
    .
}


文章来源: Why ExpenseLineRetList return null