4

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

还有员工的内置字段,有一个“职位”,SDK有一个职位,但它总是空的?

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

谢谢

这是我用来在 QuickBooks 中获取员工对象的代码,但是我需要获取自定义字段和 JobTitle(但 JobTitle 始终为空,即使它在 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
        { }
4

1 回答 1

7

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

        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();
        }
于 2013-11-13T01:16:33.370 回答