Sorting multi select on entry screen

Hi ,

Can we sort multi select on entry screen,i.e when multi select appear on screen it appear in sort order of its name rather than caption code.

Thanks

Adnan

  • 0
    Hi Adnan,
    It is clear from your above post that you want to sort a multi select field. This can be done by following the below steps.
    Let us consider Company entity entry screen with a multi select field ‘Product Categories’.

    1. Log in to the CRM as Administrator User.

    2. Navigate to the Administration -> Customization -> Companyà Fields

    3. Select the Product Categories field and click on the pencil icon.

    4. The new window ‘Maintain Lookup Selections for Product Categories’ will get open.

    5. On this screen you can see all the available values for this field.

    6. Order the fields as required. You can order the values accordingly by using the green arrows.

    7. Once you are done with the required ordering click on the save button.

    Hope this information helps!
    Regards,
    Dinesh
  • 0

    Thanks for the response... i have around 500 values in that multi-select and they are all up and down. it will be quite difficult to manually sort them. and as you keep on adding , it will again go in wrong order.. i believe writing some java-script is the solution... if someone can provide some sort of default script.. that would be great

  • 0
    Hi,
    We can sort the multiselect value by using JQuey code. For doing so please follow the below instruction

    1. Goto AdministrationàCustomizationà.

    2. Open the screen where the required field is located.

    3. Paste the below JQuery in the Custom Content of your screen.

    -------------------------------------------Code Starts ----------------------------------------------------
    $(document).ready(function(){
    sortDropDownListByText();
    });
    function sortDropDownListByText() {
    // Loop for each select element on the page.
    $("#eld>").each(function() {
    // Keep track of the selected option.
    var selectedValue = $(this).val();
    // Sort all the options by text. I could easily sort these by val.
    $(this).html($("option", $(this)).sort(function(a, b) {
    return a.text.toUpperCase() == b.text.toUpperCase() ? 0 : a.text.toUpperCase()
    }));
    // Select one option.
    $(this).val(selectedValue);
    });
    }
    -------------------------------------------Code Ends----------------------------------------------------

    4. After pasting the code in the custom content, click on the Save button.

    For this code to work, you should have CRM version 7.1 or above since only higher versions of CRM supports JQuery reference.
    Another alternative will be that you need to update from back end using SQL queries which will be ordered upon the Caption name.
    Hope this helps!
    Regards,
    Dinesh
  • 0

    Hi Dinesh

    I have tried to use your code and I am not very familiar with jQuery but it does not seem to work for me.

    Have you actually run this code? I ask because I had to remove the "src" statement to make it run at all (I replaced the sortDropDownListByText call with an alert) and when I put the call back it does not sort my "comp_sector" (Segment) field.

    Thanks

  • 0
    Hi Adnan,
    Yes, we have tested the code before providing you the same and It is working as expected. From the error it looks like it is an issue with the JQuery references at your end. You can get rid of it by following below steps.

    1. Open IE and go to http://code.jquery.com/jquery-latest.js.

    2. You will be asked to download the file. Download it.

    3. Create a new folder jQuery under WWWRoot folder which is available at the below location.

    “C:\Program Files\Sage\CRM\”<>”\WWWRoot\”.

    4. Copy and paste the downloaded file in the jQuery folder.

    OR
    In the below code sample, replace the below line
    with
    But this needs to have internet service enable on the CRM server.
    Hope this helps!
    Regards,
    Dinesh
  • 0

    Hi,

    If you want to sort all the the select or multi select on a screen, you can use this function :

    function sortDropDownListByText() {

    // Loop for each select element on the page.

    $("select").each(function() {

    // Keep track of the selected option.

    var selectedValue = $(this).val();

    // Sort all the options by text. I could easily sort these by val.

    $(this).html($("option", $(this)).sort(function(a, b) {

    return a.text.toUpperCase() == b.text.toUpperCase() ? 0 : a.text.toUpperCase()

    }));

    // Select one option.

    $(this).val(selectedValue);

    });

    }

  • 0 in reply to pprevel

    Hi, im trying to set this up for a multi select field but the code doesnt seem to be working, has anyone been able to get this working so that large multi selection lists are alphabetically sorted when editing a record and when viewing a record?

  • 0 in reply to Sufyan Iqbal PKFSCS

    hi Sufyan

    In custom content with script tags, try:

    $(function(){
    $("#selectFieldId").html($("#selectFieldId option").sort(function(opt1,opt2){
    return $(opt1).text() < $(opt2).text() && $(opt1).val() ? -1 : 1;
    }));
    });

    replacing selectFieldId with the id of the relevant select field.

    paul

  • 0 in reply to Paul C

    I must admit I've not see the problem, with my multi-selects I manually adjust the order of the items in the selection field to be the order I want them to be in (normally alphabetically) and this then displays in that order when edited the record and the values when selected all appear in alphabetical order. 

    Two Multi-selects with their values in alpha order (except the bottom one which has 'Other' as the last option)

    When saved the results show in the same order as they appeared in the list

  • 0 in reply to Paul C

    thanks Paul - that works a treat!

  • 0 in reply to Matthew Shaw

    the issue was that a particular multi select list had around 100 options in it and when adding new ones you have to manually move the new option to the correct place which takes ages - Paul's code works a treat though

  • 0 in reply to Sufyan Iqbal PKFSCS

    I've had that with one of our lists as well, I did a SQL update to reorder the capt_order based on the alphabetical order of the values within