Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QuickBooks SDK - How to get custom fields and job title?

I am wondering with using the QuickBooks SDK. I have a list of employees that I got from quickbooks, how do I get custom fields that I have set in QuickBooks for an employee?

Also with built-in fields for employee's, there is a "Job Title", with the SDK there is a JobTitle but it's always null?

Anyway to get the custom fields and the job title?

Thanks

Here is my code that I use to get the employee object inside QuickBooks, however I need to get the custom field and the JobTitle(but the JobTitle is always null, even though its set inside 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
        { }
like image 416
Silentrath Avatar asked Mar 22 '23 17:03

Silentrath


1 Answers

Okay after a lot of trial and error I have solved half of this question, the part of obtaining custom fields! You have to set the query to get them and then you can access the custom fields, but the best way I have found if you have multiple custom fields you will have to loop through them to find the field you want. Here is the code below.

        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();
        }
like image 69
Silentrath Avatar answered Apr 27 '23 03:04

Silentrath