I was looking at the Onscreen Reference to see if there's an XML request for querying jobs. I found that there's just customer query request CustomerQueryRq
and that too doesn't return the child jobs that it has.
Supposing this is how the customers & jobs centre looks like:
- Customer 1
-- Job 1
-- Job 2
-- Job 3
I was able to use CustomerQueryRq
and get the details for Customer 1
, but couldn't find anything for retrieving Job 1
.
So my question is how do I query for a job and get the parent customer it's in? I'd really appreciate any help.
EDIT: Posting my QBXML request:
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="13.0"?>
<QBXML>
<QBXMLMsgsRq onError="continueOnError">
<CustomerQueryRq requestID="1">
<FullName>Customer name</FullName>
</CustomerQueryRq>
</QBXMLMsgsRq>
</QBXML>
The Customer name
has child jobs and I'd like to query those.
ICustomerQuery
returns the list of Jobs along with the Customers list. There isn't a separate query object for Jobs. Each job has a customer as a parent. Hence, you can also retrieve the associated customer for the job.
Here's an example: I have a job J1 associated with a customer C1 in my company file. In the below C# code sample, I create a customer query object (using QB SDK 13.0) and iterate over the results. I get two results in the customer list( C1 and J1 ):
using QBXMLRP2Lib;
using Interop.QBFC13;
public class SDKApp
{
private QBSessionManager sessionMgr;
public SDKApp()
{
// in the class constructor - sessionMgr is a member variable
sessionMgr = new QBSessionManager();
}
public void GetData()
{
// open connection and begin session before data fetch - intentionally skipped this code
// during data fetch
IMsgSetRequest msgset = sessionMgr.CreateMsgSetRequest("US", 13, 0);
ICustomerQuery customerQuery = msgset.AppendCustomerQueryRq();
IMsgSetResponse msgRes = sessionMgr.DoRequests(msgset);
IResponseList responseList = msgRes.ResponseList;
if (responseList.Count > 0)
{
IResponse response = responseList.GetAt(0);
ICustomerRetList customerList = response.Detail as ICustomerRetList;
for (int i = 0; i <= customerList.Count - 1; i++)
{
ICustomerRet qbCustomer = customerList.GetAt(i);
string displayName = qbCustomer.Name.GetValue();
string entityType = "Customer";
if (qbCustomer.ParentRef != null)
{
entityType = "Job of " + qbCustomer.ParentRef.FullName.GetValue();
}
Console.WriteLine(displayName + " " + entityType);
}
}
// end session and close connection after data fetch - intentionally skipped this code
}
}