Picklist elements order in customer portal not sorted according to picklist order configuration in CRM
Picklists' values in customer portal are sorted according to the picklist's natural table order. Take this as an example:
In the CRM, the values are sorted according to the sortorderid
column, while in the customer portal values are sorted as you see them in the above image.
A solution I could successfully implement was to edit function WebserviceField::getPicklistOptions()
in file vtigercrm/include/Webservices/WebservicesField.php
as follows:
On line 381 I changed $sql = "select * from vtiger_$fieldName";
to $sql = "select * from vtiger_$fieldName ORDER BY sortorderid";
The above works for picklists that aren't role-based. In the case of role-based picklists, the values are retrieved by calling Functions::getPickListValuesFromTableForRole()
in vtigercrm/vtlib/Vtiger/Functions.php
static function getPickListValuesFromTableForRole($tablename, $roleid) {
global $adb;
$query = "select $tablename from vtiger_$tablename inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_$tablename.picklist_valueid where roleid=? and picklistid in (select picklistid from vtiger_picklist) order by sortid";
$result = $adb->pquery($query, array($roleid));
$fldVal = Array();
while ($row = $adb->fetch_array($result)) {
$fldVal [] = $row[$tablename];
}
return $fldVal;
}
The relevant part is the query: select $tablename from vtiger_$tablename inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_$tablename.picklist_valueid where roleid=? and picklistid in (select picklistid from vtiger_picklist) order by sortid
I don't really know what the function of column sortid
is (defined in table vtiger_role2picklist
):
At first I thought that maybe you could order the values of a picklist diffrently for each role. But it doesn't seem to be the case. You can't order the values in the picklist-role config here:
Changing the query to select $tablename from vtiger_$tablename inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_$tablename.picklist_valueid where roleid=? and picklistid in (select picklistid from vtiger_picklist) order by sortorderid
will keep the order given by the user under the picklist configuration. Notice the order by
field changed to sortorderid
which can be found on the picklist's values table.