Dynamics 365 v9.0 – Show Lookup Dialog is here

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”.

lookupobjects_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.

lookupobjects_lookupdialog.png

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:

  1. Ability to show specific entities
  2. Ability to show specific views
  3. Ability to make single or multi selection of the records
  4. Show Bar Code for Lookup Control on Mobile Devices(I haven’t tried this yet)

 

Hope it helps..!!

2 thoughts on “Dynamics 365 v9.0 – Show Lookup Dialog is here

  1. Anonymous

    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 …

    Reply

Leave a Reply

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