Skip to Main Content
Categories SmartForms
Created by Guest
Created on Aug 21, 2023

Sort the rules and service instance definitions alphabetically

By default when using the rules tab of a form / view the rules are not sorted alphabetically, this means that you have to go search through the list for the rule that you are trying to edit, if you have a lot of rules this costs time, granted not a lot but it does cost some time. If the rules were sorted alphabetically by default then it would be quicker to find those rules.

The below code will add a button to the rules tab that allows you to sort it so adapting it from here would be trivial.

$('#pgRuleList').find('.toolbar-wrapper').append('<div class="toolbar-divider" id=""></div><a href="javascript:;" onclick="(function (){ const rules = Array.from(document.querySelectorAll(\'.input-control-group\')); rules.forEach(ul => { const rule = Array.from(ul.querySelectorAll(\'li\')); rule.sort((a, b) => { const textA = a.textContent.trim(); const textB = b.textContent.trim(); return textA.localeCompare(textB); }); ul.innerHTML = \'\'; rule.forEach(li => ul.appendChild(li));});})();" tabindex="0" class="toolbar-button filter" id="pgSortRules" title="Sort Rules"><span class="button-l"></span><span class="button-c"><span class="button-icon"></span><span class="button-text">Sort Rules</span></span><span class="button-r"></span></a>')


This is also true for when you are trying to add a method to a SmartObject. The list of service instances are not sorted alphabetically, again this is a massive time suck when you times it by the number of developers that have to manually search for this information. The below will sort them for you as well.

$('ul#ServiceObjectMethodTreeBrowserTree ul li').sort(function(a,b){return ($(b).text() < $(a).text() ? 1: -1);}).appendTo('ul#ServiceObjectMethodTreeBrowserTree ul');$('ul#SODesignerServiceMethodTree ul li').sort(function(a,b){return ($(b).text() < $(a).text() ? 1: -1);}).appendTo('ul#SODesignerServiceMethodTree ul');$('ul#ServiceMethodDialogTree ul li').sort(function(a,b){return ($(b).text() < $(a).text() ? 1: -1);}).appendTo('ul#ServiceMethodDialogTree ul');


Feel free to use / adapt the code as necessary.

  • Attach files