I want to set the conditionally Order_BY in rest API e.g("B" comes before "A"and "D" comes before "C" means the out put is appear like this "BADC") please help me if it is possible
$get_entry_list_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => 'Accounts',
//The SQL WHERE clause without the word "where".
'query' => $query,
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => " How to set Conditional Order By "
);
I guess BADC that you mentioned is column's name. That should be done with some code like this:
<?php
$order_by = $_POST['order_by']; // order_by's format is like this: B:asc;A:asc;D:desc;C:desc;
$order_by_str = ""; // to store a query statement for 'order by'
$order_by_array = explode(';', $order_by);
foreach ($order_by_array as $order_item) {
$order_item_array = explode(':', $order_item);
$order_by_str .= "," . $order_item_array[0] . " " . $order_item_array[1];
}
$order_by_str = substr($order_by_str, 1); // result for order_by
This is a known bug.
There is a bug report with a proposed fix here Defect 66206: REST V4_1 API,function get_entry_list didn't work with the order_by attribute
Applying the proposed fix worked for me.