Accessing the names of the attributes or controls Xrm.Page object model

1.Access a specific subgrid control by name.

Below function will be written The names of all the subgrid controls
 if(ctrl.getControlType() == "subgrid")

2. Show the names of all attributes in a form with their type

function (att, i) {
 console.log(att.getName() + " : " + att.getAttributeType())

3. Show the valid option values for optionset attributes

function (att, i) {
 if (att.getAttributeType() == "optionset") {
  var options = att.getOptions();
  var optionsLength = options.length;
  for (var i = 0; i < optionsLength; i++) {
   var option = options[i];
   console.log("   value: " + option.value + " Label: " + option.text)




Form programming methods

The following table lists the form programming methods available for updated entities only.

Method Description
Xrm.Page.context.client.getClient Returns a value to indicate which client the script is executing in.
Xrm.Page.context.client.getClientState Returns a value to indicate the state of the client.
Xrm.Page.context.getUserName Returns the name of the current user. Gets a string for the value of the primary attribute of the entity. Asynchronously refreshes the data of the form without reloading the page. Saves the record asynchronously with the option to set callback functions to be executed after the save operation is completed. attribute.getIsPartyList Determines whether a lookup attribute represents a partylist lookup.
Xrm.Page.ui control.clearNotification Removes a message already displayed for a control.
Xrm.Page.ui control.setNotification Displays a message near the control to indicate that data is not valid.
Xrm.Page.ui.clearFormNotification Use this method to remove form level notifications.
Xrm.Page.ui.setFormNotification Use this method to display form level notifications.
Xrm.Page.ui control.addCustomFilter Use fetchXml to add additional filters to the results displayed in the lookup. Each filter will be combined with any previously added filters as an ‘AND’ condition.
Xrm.Page.ui control.setShowTime Specifies whether a date control should show the time portion of the date.
Xrm.Utility.alertDialog Displays a non-blocking alert dialog with a callback function.
Xrm.Utility.confirmDialog Displays a non-blocking confirm dialog with different callbacks depending on the button clicked by the user.

PreSearch Event in Microsoft Dynamics 365

PreSearch event for updated entities

The new PreSearch event occurs just before the search dialog box opens when you set a lookup value. This event does not have user interface to set an event handler in the application; it can only be set using the Xrm.Page.ui control.addPreSearch method. Use this event with the addCustomFilter, addCustomView and setDefaultView methods to control the views opened when people search for a record to set as the value of a lookup field.

Use this method to apply changes to lookups based on values current just as the user is about to view results for the lookup.

Type: Function to add.

This method is only available for Updated entities.

The argument is a function that will be run just before the search to provide results for a lookup occurs. You can use this handler to call one of the other lookup control functions and improve the results to be displayed in the lookup.


Use this method to remove event handler functions that have previously been set for the PreSearch event.

Type: Function to remove.

This method is only available for Updated entities.