Setting a Default Search Field and Search Operator for Lookups in Infor CRM

In the Infor CRM (Saleslogix) web client, the Lookup dialogs will default the search field to the first field in the lookup results layout. The operator will default to a default for the data type of the search field. However, this behavior can be changed with some Javascript on a lookup-by-lookup basis.

Let’s say we want this default to be different based on some other conditions in the data, or maybe you just want the layout one way, but the default search to not just be the first field in the layout. This code below will change this behavior. Create a C# Code LoadAction, paste in the code below, and set the value for the Lookup you want to change this behavior for, as well as the default field and operator you want the lookup to use.

// set the lookup, default search field, and default operator here
var lookupId = lueContact.ClientID;
var defaultField = "Email"; // <- SData property name
var defaultOperator = "eq"; // <- SData operator (eq, gt, lt, etc)

// this code can remain unchanged
ScriptManager.RegisterStartupScript(this, GetType(), "script_CustomizeLookup", @"
require(['dojo/aspect', 'Sage/UI/SearchConditionWidget'], function(aspect, SearchConditionWidget) { 
    aspect.after(SearchConditionWidget.prototype, '_setToDefaultOperator', function() { 
        var lookupId = '%LOOKUP%';
        if (this.id.toLowerCase().substring(0, lookupId.length) == lookupId.toLowerCase()) {
            this._operatorSelect.set('value', '%OP%'); 
        }
    }); 
    aspect.after(SearchConditionWidget.prototype, '_setToDefaultField', function() { 
        var lookupId = '%LOOKUP%';
        if (this.id.toLowerCase().substring(0, lookupId.length) == lookupId.toLowerCase()) {
            this._fieldNameSelect.set('value', '%FIELD%');
        }
    }); 
});
".Replace("%LOOKUP%", lookupId).Replace("%FIELD%", defaultField).Replace("%OP%", defaultOperator), true);

Note, the defaultField value must be a valid SData property for the entity the lookup is for, and the operator must be a valid operator for the data type of that property.

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!