Hello everyone,
Microsoft has recently released Developer Guide for Dynamics 365 v9.0. From now on wards, only online version of documentation is available. You can find latest documentation here
One of the new Dev feature caught my eye was the ability to show Lookup Dialog using Xrm.Utility.lookupObjects method. Earlier, we used to go with unsupported method to show Lookup Dialog which is no longer required. Here is how it has to be done in v9.0 onwards.
Lets assume a scenario where we have a custom ribbon button “Assign”.
when user clicks on this ribbon button a Lookup Dialog has to be shown with list of system users. On selection of a specific user, owner field has to be updated with it and record has to saved.
Following is the code which does the required functionality and also
- Limits list of views to be shown
- Sets Return Value to Single
This new method expects an object with list of parameters to be passed and success and Cancel callback functions.
function SelectNewAssignee() { var lookupOptions = {}; //list of entities to be displayed lookupOptions.entityTypes = ["systemuser"]; //entity to be shown bydefault in lookup dialog lookupOptions.defaultEntityType = "systemuser"; //default view lookupOptions.defaultViewId = "{00000000-0000-0000-00AA-000010001019}"; //Allow Multiple Records to be selected or not lookupOptions.allowMultiSelect = false; //List of views to be available lookupOptions.viewIds = ["{00000000-0000-0000-00AA-000010001019}", "{00000000-0000-0000-00AA-000010001020}"]; //This is for Mobile Devices //lookupOptions.showBarcodeScanner = false; Xrm.Utility.lookupObjects(lookupOptions).then(AssigneeSuccessCallback, AssigneeCancelCallback) } //Success Callback for Lookup Dialog //Gets Array of selected records in the lookup dialog function AssigneeSuccessCallback(selectedItems) { if (selectedItems != null && selectedItems.length > 0) { var newAssignee = [{ id: selectedItems[0].id, typename: selectedItems[0].typename, name: selectedItems[0].name }]; Xrm.Page.getAttribute("ownerid").setValue(newAssignee); Xrm.Page.data.entity.save(); } } function AssigneeCancelCallback() { }
Other capabilities of this method:
- Ability to show specific entities
- Ability to show specific views
- Ability to make single or multi selection of the records
- Show Bar Code for Lookup Control on Mobile Devices(I haven’t tried this yet)
Hope it helps..!!
Is this not supported in v9.0.2 anymore? There seems to be some internal error.
Uncaught ReferenceError: LookupObjectsWithCallback is not defined
at Mscrm.XrmInternal.lookupObjects (global.ashx?ver=2066038800:formatted:12236)
at Function.Xrm.Internal.lookupObjects (global.ashx?ver=2066038800:formatted:3594)
at Mscrm.XrmUtility.lookupObjects (global.ashx?ver=2066038800:formatted:11034)
at Function.Xrm.Utility.lookupObjects (global.ashx?ver=2066038800:formatted:3946)
at eval (eval at lookupObjects (global.ashx?ver=2066038800:formatted:12236), :8:29)
at Mscrm.XrmInternal.lookupObjects (global.ashx?ver=2066038800:formatted:12236)
at Function.Xrm.Internal.lookupObjects (global.ashx?ver=2066038800:formatted:3594)
at Mscrm.XrmUtility.lookupObjects (global.ashx?ver=2066038800:formatted:11034)
at Function.Xrm.Utility.lookupObjects (global.ashx?ver=2066038800:formatted:3946)
at …
Yes, I get the same error