Group sort for incidents not working in an alphabetical order

phr
Tera Contributor

Hi All,

 

When the group by filter is applied on the "state" field, the results are not presented in the alphabetical order.

Is there any way to fix this issue?

Attaching image for Reference.

phr_0-1725954291249.png

 

1 ACCEPTED SOLUTION

New Developer_S
Giga Sage

@phr 

In ServiceNow, when you apply a group by filter on fields such as the state field, the grouping results may not appear in alphabetical order because Service Now groups them based on their underlying values (e.g., the order field or the numeric value in the choice table) rather than their label values.
but you can try below options:
1.Set the Order of Choice Values ( Which is a easy way to implement) 

 

  • The state field in Service Now is typically a choice list field, and each choice has an Order field that controls the sorting of the values.You can update the Order of each state option to be in alphabetical order manually.
  • 2. Modify the Sorting Behavior with a Script (Client Script / UI Script)

     

    • Create a Client Script or use a UI Action to manipulate the results and reorder them based on the alphabetical order of the labels.
    • Example :
    • function onLoad() {
      var gr = new GlideRecord('your_table_name');
      gr.query();
      var sortedArray = [];
      while (gr.next()) {
      sortedArray.push(gr.state.getDisplayValue());
      }

      // Sort the array alphabetically
      sortedArray.sort();

      // Now display the sorted data
      g_form.setValue('state', sortedArray.join(', '));
      }

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.

Best Regards.

 

View solution in original post

2 REPLIES 2

New Developer_S
Giga Sage

@phr 

In ServiceNow, when you apply a group by filter on fields such as the state field, the grouping results may not appear in alphabetical order because Service Now groups them based on their underlying values (e.g., the order field or the numeric value in the choice table) rather than their label values.
but you can try below options:
1.Set the Order of Choice Values ( Which is a easy way to implement) 

 

  • The state field in Service Now is typically a choice list field, and each choice has an Order field that controls the sorting of the values.You can update the Order of each state option to be in alphabetical order manually.
  • 2. Modify the Sorting Behavior with a Script (Client Script / UI Script)

     

    • Create a Client Script or use a UI Action to manipulate the results and reorder them based on the alphabetical order of the labels.
    • Example :
    • function onLoad() {
      var gr = new GlideRecord('your_table_name');
      gr.query();
      var sortedArray = [];
      while (gr.next()) {
      sortedArray.push(gr.state.getDisplayValue());
      }

      // Sort the array alphabetically
      sortedArray.sort();

      // Now display the sorted data
      g_form.setValue('state', sortedArray.join(', '));
      }

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.

Best Regards.

 

Hi @New Developer_S ,

 

Thank you.