Search code examples
javascriptdynamics-crmdynamics-crm-online

Show all values in lookup field - Dynamics CRM 2015 Web


I have found an answer to show all values in lookup field for on-premise by changing a value in the db - however, this is web version and don't have access to the db.

Can I do this in javascript? If so, can someone point me to a reference? I can't find what I am looking for on the web.

I.e. I have 12 lookup values, but only displays 10 without having to select 'lookup more record.' I want to the filed to show all 12.

Thanks.


Solution

  • I didn't know this was a configurable option in CRM on-premise, but even so it's for sure not possible to change Dynamics CRM (365) Online. One of the online systems limitations is that you don't have access to the database, registry, web.config etc.

    What you could do (for some of the lookups) is replace them with a web resource, which emulates the lookup behaviour. This is quite simple, using for example select2.

    It can directly call the REST service and dynamically populate based on what the user types.

    An an example on how to use it with the REST service would be this:

    var baseUrl = Xrm.Page.context.getClientUrl() + "/xrmservices/2011/OrganizationData.svc/";
    
    var crmLookupType = "Account"
    var crmLookupSearchField = "Name"
    var crmLookupIdField = "AccountId"
    var url = baseUrl + crmLookupType + "Set";
    
    $(#mySelect).select2({
        ajax: {
            url: url,
            dataType: 'json',
            data: function (term, page, context) {
                return {
                    "$select": crmLookupIdField + "," + crmLookupSearchField,
                    "$filter": "startswith(" + crmLookupSearchField + ",'" + term.term + "')"
                };
            },
            delay: 250,
            cache: false,
            processResults: function (data) {
                if (data.d.results && data.d && data.d.results) {               
                    return {
                        results: $.map(data.d.results, function (item) {
                            return {
                                text: item[crmLookupSearchField],
                                id: item[crmLookupIdField]
                            };
                        })
                    };
                }
                else {
                    return [];
                }
            }
        },
        minimumInputLength: 2
    }).on("select2:selecting", function (e) {
        $(e.currentTarget).children().remove();
    });
    

    Afterwards, when an item is selected you can populate the original lookup field (which you hide on the form) with the selected ID.