Why ExpenseLineRetList return null

北战南征 提交于 2019-12-13 04:42:16

问题


I saw this link and I notice we have the same problem, and his question still didn't answer yet.

Here is the question.

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();
            }
        }

    }

Why ExpenseLineRetList is null?


回答1:


A check request will not include the detail lines of the check unless you include it in your query. By adding the IncludeLineItems setting, you'll get access to the Expense or Item lists of the check (a check could have Expense lines, Item lines, or both). You'll want to change to include the following:

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

I would also suggest that you check the response code before trying to get the response detail so you can better handle errors:

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;
    .
    .
    .
}


来源:https://stackoverflow.com/questions/22754202/why-expenselineretlist-return-null

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