QuickBooks SDK - 如何获取自定义字段和职称?

时间:2013-11-11 02:08:00

标签: c# desktop-application quickbooks

我想知道使用QuickBooks SDK。我有一份从快速书中获得的员工列表,如何获得我在QuickBooks中为员工设置的自定义字段?

对于员工的内置字段,还有一个“职称”,SDK有一个JobTitle,但它总是为空?

无论如何要获得自定义字段和职称?

由于

这是我用来在QuickBooks中获取员工对象的代码,但是我需要获取自定义字段和JobTitle(但JobTitle始终为null,即使它在QuickBooks中设置)。

using QBFC12Lib;


        QBSessionManager sessionManager = null;

        try
        {
            // create the session manager
            sessionManager = new QBSessionManager();
            sessionManager.OpenConnection("", "Test Employee");
            sessionManager.BeginSession(@"C:\PathTo\CompanyFile.qbw", ENOpenMode.omDontCare);

            //Create the message set request object to hold our request
            IMsgSetRequest request = sessionManager.CreateMsgSetRequest("US", 8, 0);
            request.Attributes.OnError = ENRqOnError.roeContinue;

            // create the employee query
            IEmployeeQuery employeeQuery = request.AppendEmployeeQueryRq();

            // send the request and get the response from QuickBooks
            IMsgSetResponse responseMsgSet = sessionManager.DoRequests(request);
            IResponse response = responseMsgSet.ResponseList.GetAt(0);
            IEmployeeRetList employeeRetList = (IEmployeeRetList)response.Detail;

            if (employeeRetList != null)
            {
                for (int i = 0; i < employeeRetList.Count; i++)
                {
                    // create employee item
                    IEmployeeRet employee = employeeRetList.GetAt(i);

                    // only get active employees
                    if (employee.IsActive.GetValue())
                    {
                        string firstName = employee.FirstName.GetValue();
                        string jobTitle = employee.JobTitle.GetValue();
                    }
                }
            }
        }
        catch
        { }

1 个答案:

答案 0 :(得分:5)

好的经过大量的试验和错误我已经解决了这个问题的一半,获得自定义字段的部分!您必须设置查询才能获取它们,然后您可以访问自定义字段,但如果您有多个自定义字段,我必须找到最佳方法,您必须遍历它们才能找到所需的字段。这是下面的代码。

        employeeQuery.IncludeRetElementList.Add("DataExtRet");
        employeeQuery.OwnerIDList.Add("0");

        for (int x = 0; x < employee.DataExtRetList.Count; x++)
        {
            // get the dataExt object, now you have access to the custom field
            IDataExtRet dataExt = employee.DataExtRetList.GetAt(x);
            string customFieldName = dataExt.DataExtName.GetValue();
            string value = dataExt.DataExtValue.GetValue();
        }