Monday, 18 June 2018

How to show Filtered Lookup Dialog in Dynamics CRM through JavaScript

Apply Custom Filter on Lookup Field in Dynamics CRM using Script
Description:
In this example we explain that how to open filtered Lookup Dialog in Dynamic CRM using JavaScript. Or how to display Filtered Lookup Popup in Dynamic 365 using JavaScript. Or how to show Filtered Lookup Dialog box using JavaScript in Dynamic CRM.

Here we demonstrate that how to apply custom filter on Lookup and display on Modal Popup Dialog Box in Dynamic CRM using JavaScript. Or Filtered Lookup view on pre-selected value on Dynamic CRM form using JavaScript. Or selecting Lookup Value Dynamically using JavaScript.
Code:

function openFilteredLookup(defaultType, defaultViewId, currentObjectType, currentId, rDependentAttr, rId, rType, relationshipId) {

            var functionName = "openLookup";

            try {



                if (isValid(currentObjectType) && isValid(currentId)) {

                    //prepare lookup url

                    var url = "/_controls/lookup/lookupinfo.aspx?AllowFilterOff=0&DefaultType=" + defaultType + "&DefaultViewId=%7b" + defaultViewId + "%7d&DisableQuickFind=0&DisableViewPicker=1&IsInlineMultiLookup=0&LookupStyle=single&ShowNewButton=1&ShowPropButton=1&browse=false&currentObjectType=" + currentObjectType + "&currentid=%7b" + currentId + "%7d&dType=1&mrsh=false&objecttypes=" + defaultType + "&rDependAttr=" + rDependentAttr + "&rId=%7b" + rId + "%7d&rType=" + rType + "&relationshipid=" + relationshipId + "";

                } else {

                    //prepare lookup url

                    var url = "/_controls/lookup/lookupinfo.aspx?AllowFilterOff=0&DefaultType=" + defaultType + "&DefaultViewId=%7b" + defaultViewId + "%7d&DisableQuickFind=0&DisableViewPicker=1&IsInlineMultiLookup=0&LookupStyle=single&ShowNewButton=1&ShowPropButton=1&browse=false&dType=1&mrsh=false&objecttypes=" + defaultType + "&rDependAttr=" + rDependentAttr + "&rId=%7b" + rId + "%7d&rType=" + rType + "&relationshipid=" + relationshipId + "";

                }



                //Set the Dialog Width and Height

                var DialogOptions = new Xrm.DialogOptions();

                //Set the Width

                DialogOptions.width = 500;

                //Set the Height

                DialogOptions.height = 550;



                //open dialog

                Xrm.Internal.openDialog(Mscrm.CrmUri.create(url).toString(), DialogOptions, null, null, CallbackFunction);



                //Set the variable to false

                isOnLoad = false;



            } catch (e) {

                throwError(e, functionName);

            }

        }



0 comments:

Post a Comment