Question

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?

Was it helpful?

Solution

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;
    .
    .
    .
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top