Order_by not working for webservice method

Hello All ,

I am calling last inserted lead with limit 10 its coming but order by desc is not working ??

i seems like it was bug in sugar crm ( Bug :59526 )

http://forums.sugarcrm.com/f6/need-help-how-sort-records-order_by-descending-order-84127/

but how abount suite crm ??

is there any way to achieve this ??

My code is like this but its not coming in desc order ? :frowning:

<?php error_reporting(E_ALL); // specify the REST web service to interact with $url = 'localhost/suitecrm7.1.1/service/v4_1/rest.php'; // Open a curl session for making the call $curl = curl_init($url); // Tell curl to use HTTP POST curl_setopt($curl, CURLOPT_POST, true); // Tell curl not to return headers, but do return the response curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Set the POST arguments to pass to the Sugar server $parameters = array( 'user_auth' => array( 'user_name' => 'admin', 'password' => md5('admin'), ), ); $json = json_encode($parameters); $postArgs = array( 'method' => 'login', 'input_type' => 'JSON', 'response_type' => 'JSON', 'rest_data' => $json, ); curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs); // Make the REST call, returning the result $response = curl_exec($curl); // Convert the result from JSON format to a PHP array $result = json_decode($response); echo "
";
print_r($result);
if ( !is_object($result) ) {
    die("Error handling result.\n");
}
if ( !isset($result->id) ) {
    die("Error: {$result->name} - {$result->description}\n.");
}
// Echo out the session id
echo $result->id."
"; $session = $result->id; // Let us fetch detail of a Payment $fields_array = array('name','amount','date_entered'); $parameters = array( 'session' => $session, //Session ID 'module_name' => 'p_payment', //Module name 'query' => " p_payment.name IS NOT NULL ", //Where condition without "where" keyword 'order_by' => " p_payment.date_enterded ", //$order_by 'offset' => 0, //offset 'select_fields' => $fields_array, //select_fields 'link_name_to_fields_array' => array(array()),//optional 'max_results' => 10, //max results 'deleted' => 'false', //deleted ); $json = json_encode($parameters); print_r($json); $postArgs = array( 'method' => 'get_entry_list', 'input_type' => 'JSON', 'response_type' => 'JSON', 'rest_data' => $json, ); curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs); $response = curl_exec($curl); // print_r($response); // Convert the result from JSON format to a PHP array $result = json_decode($response); print "
";
print_r($result);

die;

is there any way to resolve this

:ohmy: :blink: :blink: :S

is there any way your help will be very much appreciated ??

Hi All ,

Finally i found the secondary option to fix this problem ,

All You need is your own method which you can use to fetch data .

add this method to suitecrm/service/core/SugarWebServiceImpl.php .

Example

let’s say i have modules inventory and product which has m-1 relationship

so in simple words many inventory can be map with one product

i want available inventory count with product prize so , i created a new method get_inventory_count_price.


function get_inventory_count_price($session, $model_number){

	$GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_count_relation');
	$error = new SoapError();
	// check the access for particular sesstion 
	if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
		$error->set_error('invalid_login');
		$GLOBALS['log']->info('End: SugarWebServiceImpl->get_available_modules');
		return;
	} // if
	$qur = "SELECT price,id FROM aos_products where part_number='".$model_number."' AND deleted=0 LIMIT 0,1";
	$res = $GLOBALS['db']->query($qur);
	$row = $GLOBALS['db']->fetchByAssoc($res);

	$focus = BeanFactory::getBean('AOS_Products', $row['id']);      //Retrieve bean
	$inventory = $focus->get_linked_beans('aos_products_i_inventory_1','i_inventory');  // loading relation ship
	$count = 0 ;
	foreach ($inventory as $product) {
		if($product->status=='available'){
			$count++;
		}
	}
	$GLOBALS['log']->info('End: SugarWebServiceImpl->get_count_relation');
	return array(
		'price' => $row['price'],
		'count' => $count,
		);

}

so create your own methods for use .

Thank you for your time and support