You need to sign in to do that
Don't have an account?
Angela Stratman
Change the order of a picklist on a Visualforce page
We have a Create New Work Order page in Field Service Lightning (FSL), as a Visualforce page. One of the fields is a Work Type (picklist), but the order of the picklist is crazy, and I would like it to be in alphabetical order. I have no idea if this is even possible or what order it is even pulling in. Below are the only 2 parts of the code that contain Work Order Type. I am not a developer, so any help is GREATLY appreciated!
<tr>
<td>
<div class="slds-form-element">
<label class="slds-form-element__label">Work Type *</label>
</div>
</td>
<td>
<div class="slds-form-element__control">
<select id="work-type" class="slds-input" data-api="WorkTypeId">
<option value=""></option>
</select>
</div>
</td>
</tr>
_________________________________________________________________________________
var getPicklistOptions = function() {
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.Kappus_NewWorkOrderButtonController.getWorkTypes}',
function(workTypes, event) {
if (event.statusCode === 200) { Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.Kappus_NewWorkOrderButtonController.getOptions}',
function(options, event) {
if (event.statusCode === 200) {
var options1 = '',
options2 = '',
options3 = '';
workTypes.forEach(function(workType) {
options1 += '<option value="' + workType['Id'] + '">' + workType['Name'] + '</option>';
});
<tr>
<td>
<div class="slds-form-element">
<label class="slds-form-element__label">Work Type *</label>
</div>
</td>
<td>
<div class="slds-form-element__control">
<select id="work-type" class="slds-input" data-api="WorkTypeId">
<option value=""></option>
</select>
</div>
</td>
</tr>
_________________________________________________________________________________
var getPicklistOptions = function() {
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.Kappus_NewWorkOrderButtonController.getWorkTypes}',
function(workTypes, event) {
if (event.statusCode === 200) { Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.Kappus_NewWorkOrderButtonController.getOptions}',
function(options, event) {
if (event.statusCode === 200) {
var options1 = '',
options2 = '',
options3 = '';
workTypes.forEach(function(workType) {
options1 += '<option value="' + workType['Id'] + '">' + workType['Name'] + '</option>';
});
1) Could you post code of the controller Kappus_NewWorkOrderButtonController , the getOptions method is creating the list we can do sorting at that place , it would be better approach.
2) Other option we can do is , do sorting on vf page once data is returned from controller by visualforce remoting
I am assuming from the piece of code you shared
This will do the comparison and sorting on alphabet basis
call this method
Final code output be some thing like this
Hope this helps!
@RemoteAction
@ReadOnly
global static List<WorkType> getWorkTypes() {
List<WorkType> workTypes = new List<WorkType>();
workTypes.addAll([SELECT Id, Name FROM WorkType]);
return workTypes;
}
use order by clause for sorting
[SELECT Id, Name FROM WorkType order by Name ASC]
Hope this helps!