back to top

Changing the default Sort of a Lookup Control in the Infor CRM Web Client

Normally, a lookup in the Infor CRM Web Client is determined based on the order of the columns as defined at design times. The search of the lookup defaults to the left most column in the layout and this is also the default sort of things that are returned.

There is a way to change a particular lookup’s default sort of the result set. Lets take a look at how.

The following code is the complete sample. Let’s see that and then I will explain it.

var lookupId = "lueProduct";
var defaultField = "ProdPackageKitType";

ScriptManager.RegisterStartupScript(this, GetType(), "script_CustomizeLookup", @"
    require(['dojo/aspect', 'Sage/UI/SDataLookup'], function(aspect, SDataLookup) {
        aspect.before(SDataLookup.prototype, 'initGrid', function() {
            if (this.id.indexOf('%LOOKUP%') !== -1) {
                this.storeOptions.sort = [{attribute:'%FIELD%'}];
            }
        });
    });
".Replace("%LOOKUP%", lookupId).Replace("%FIELD%", defaultField), true);

The lines

var lookupId = "lueProduct";
var defaultField = "ProdPackageKitType";

Define the name of the lookup control we want to modify (lueProduct) and what the property within the lookup layout we want to be the default sort field (ProdPackageKitType). The reason this code is written this way is to allow for it to be re-used with just the names needing to be replaced.

Most of the rest of the code is setting up a string that will be injected onto the page by the ScriptManager. This string is a dojo function utilizing aspect before to modify the base SDataLookup widget’s initGrid function. Within this function we are modifying the storeOptions.sort attribute to be the field we want to sort by. You could also add an asc or desc to change the direction.

ScriptManager.RegisterStartupScript(this, GetType(), "script_CustomizeLookup", @"
    require(['dojo/aspect', 'Sage/UI/SDataLookup'], function(aspect, SDataLookup) {
        aspect.before(SDataLookup.prototype, 'initGrid', function() {
            if (this.id.indexOf('%LOOKUP%') !== -1) {
                this.storeOptions.sort = [{attribute:'%FIELD%'}];
            }
        });
    });"

The final bit of code replaces the wildcards %LOOKUP% and %FIELD% with the names of the lookup and entity property defined at the start of the script.

....Replace("%LOOKUP%", lookupId).Replace("%FIELD%", defaultField), true);

All of this code would be added to the server-side Load Action of the quickform that the control resides on.

Note that the sort field needs to be a property in the lookup result layout.

Contact Customer FX for your CRM project
We let our expertise speak for itself - let us know how our all-star team can help on your CRM project
About the Author
Kris Halsrud
Kris Halsrud
Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Infor CRM Sync for Exchange: Action Required by August 31, 2026

Using Infor CRM Sync for Exchange with Microsoft 365? Your Exchange administrator must update tenant settings by August 31, 2026 to prevent sync disruption.

[Webinar] What’s Coming Next for Infor CRM SLX and Why v10 Matters

See what’s coming next for Infor CRM SLX, including new marketing workflows, automation improvements, and reasons to consider upgrading to v10.

Disable Caching in Infor CRM SLX Web Client

In the rare case caching is causing issues in the Infor CRM SLX web client, it is possible to disable specific types of caching by making edits using Application Architect, and then deploying.

Exploring AI Options for Infor CRM v10

I've started taking a closer look at the AI capabilities built into Infor CRM v10. Over the next several posts, I'll share what I learn. From the built-in features and supported AI providers to implementation considerations, costs, and practical use cases.

Infor CRM SLX 10.0: Delegate Ownership Changes for “Everyone” Records

Learn how the new EveryoneOwnerAssignment secured action in Infor CRM SLX 10.0 allows designated users to change ownership of Everyone-owned records without requiring Administrator access.

Related Articles

Infor CRM Sync for Exchange: Action Required by August 31, 2026

Using Infor CRM Sync for Exchange with Microsoft 365? Your Exchange administrator must update tenant settings by August 31, 2026 to prevent sync disruption.

[Webinar] What’s Coming Next for Infor CRM SLX and Why v10 Matters

See what’s coming next for Infor CRM SLX, including new marketing workflows, automation improvements, and reasons to consider upgrading to v10.

Disable Caching in Infor CRM SLX Web Client

In the rare case caching is causing issues in the Infor CRM SLX web client, it is possible to disable specific types of caching by making edits using Application Architect, and then deploying.

Exploring AI Options for Infor CRM v10

I've started taking a closer look at the AI capabilities built into Infor CRM v10. Over the next several posts, I'll share what I learn. From the built-in features and supported AI providers to implementation considerations, costs, and practical use cases.

Related Videos