Paginate JobOrder search results

Forum for users and developers of Bullhorn's Webservices API suite

Moderators: StaffingSupport, s.emmons, BullhornSupport

Post Reply
blackairplane
User
Posts: 4
Joined: Tue Jan 29, 2013 12:33 pm

Paginate JobOrder search results

Post by blackairplane » Tue Jan 29, 2013 12:41 pm

I'm having trouble paginating my search results within the JobOrder entity. I am using a form to submit search terms, and then paginate based upon whether more than 20 results are returned. Any idea how to do this?

Code: Select all

//Test URL = listing.php?record=61&terms=developer
	$params = array(
			'trace' => 1,
			'soap_version' => SOAP_1_1);
	$BHclient = new SoapClient("https://api.bullhornstaffing.com/webservices-1.1/?wsdl",$params);
	
	$username = "api-username";
	$password = "api-password";
	$apiKey = "AAAAAAAA-AAAA-AAAA-AAAAAAAAAAAAAAAA";
	
	$session_request = new stdClass();
	$session_request->username = $username;
	$session_request->password = $password;
	$session_request->apiKey = $apiKey;
	
	$API_session = $BHclient->startSession($session_request);
	$API_currentSession = $API_session->return;

	
	
	// Format query
	if (isset($_GET['terms'])) {
		$searchTerms = explode(',', rawurldecode($_GET['terms']));
	} else {
		$searchTerms = explode(',', $_POST["JobSearch"]);
	}
	$whereParameter = "isDeleted=0 AND isOpen=1 AND status='Accepting Candidates'";
	if (!empty($searchTerms)) {
		$whereParameter .= " AND (";
		foreach($searchTerms as $key => $searchTerm) {
			if ($key != 0) {
				$whereParameter .=" AND ";
			}
			$whereParameter .= "title LIKE '%" . ltrim($searchTerm) . "%'";
			$whereParameter .= " OR publicDescription LIKE '%" . ltrim($searchTerm) . "%'";
		}
		
		$whereParameter .= ") ORDER BY dateAdded DESC";
		
		//Get List of Jobs
		$query_array = array(
			'entityName' => 'JobOrder',
			'maxResults' => 20,
			'where' => $whereParameter,
			'parameters' => array()
		);
		
		// Determine if pagination request
		if (isset($_GET['record']) && isset($_GET['terms'])) { 
			$query_array['limit'] = $_GET['record'];
		}
		
		$SOAP_query = new SoapVar($query_array, SOAP_ENC_OBJECT, "dtoQuery", "http://query.apiservice.bullhorn.com/");
		
		$request_array = array(
			'session' => $API_currentSession,
			'query' => $SOAP_query
		);
		
		$SOAP_request = new SoapVar($request_array,  SOAP_ENC_OBJECT, "query", "http://query.apiservice.bullhorn.com/");
		try {
				$queryResult = $BHclient->query($SOAP_request);
			} catch (SoapFault $fault) {
				var_dump($BHclient->__getLastRequest());
				echo"FAILED";
				die($fault->faultstring);
			}
	
		// Add each JobOrder Id to an array
		if (is_array($queryResult->return->ids)) {
			foreach ($queryResult->return->ids as $value) {
				$findId = new SoapVar($value, XSD_INTEGER,"int","http://www.w3.org/2001/XMLSchema");
				$findId_array[] = $findId;
			}
			
			$find_request = array(
					'session' => $API_currentSession,
					'entityName' => 'JobOrder',
					'ids' => $findId_array
			);
			try {
				$findResult = $BHclient->findMultiple($find_request);
			} catch (SoapFault $fault) {
				var_dump($BHclient->__getLastRequest());
				die($fault->faultstring);
			}
		}	
	} 

s.emmons
User
Posts: 333
Joined: Wed Dec 31, 1969 8:00 pm

Re: Paginate JobOrder search results

Post by s.emmons » Tue Feb 19, 2013 4:39 pm

Hi blackairplane,

The query operation returns a list IDs, so how you choose to organize them is at your discretion. You can use the findMultiple operation to retrieve batches of 20 records at a time from the list and paginate them that way, or could adjust the query to run subsequently ordered by ID number, with each subsequent query looking for IDs greater than the last ID in the previous set of results.
Sam Emmons
Enterprise Team Lead
BULLHORN
US Support 617-478-9126

blackairplane
User
Posts: 4
Joined: Tue Jan 29, 2013 12:33 pm

Re: Paginate JobOrder search results

Post by blackairplane » Thu Mar 07, 2013 11:44 am

Thanks so much for your help on this. Got it working. Stuck on this other issue though: http://supportforums.bullhorn.com/viewt ... 32&t=14471 Do you have any idea there?

Post Reply