CRM 2013 New Client API Methods

Posted by on September 23, 2013  |  commentsComments (3)

With CRM 2013, Microsoft is providing some exciting new methods we can use with the JavaScript SDK on the entity forms.  Some highlights are an easier way to set the form dirty, custom lookup filters, and a supported way to display form notifications as well as field specific notifications.  See below for a full comprehensive list with details.

Context

  • Xrm.Page.context.client.getClient()
    • Returns “Outlook”, “Web”, or “Mobile”
  • Xrm.Page.context.client.getClientState()
    • Returns “Online” or “Offline”
    • Xrm.Page.context.isOutlookOnline and isOutlookClient are now deprecated

Data

  • Xrm.Page.data.refresh()
    • Asynchronously refresh data on form without reloading the page
    • Can pass in a callback to execute on error or success
  • Xrm.Page.data.save()
    • Asynchronously save the form
    • Can pass in a callback to execute on error or success
  • Xrm.Page.data.getIsValid()
    • Returns a boolean telling whether the form can be saved or not
  • Xrm.Page.data.setFormDirty()
    • Sets the form as dirty

Entity

  • Xrm.Page.data.entity.getPrimaryAttributeValue()
    • Returns a string value of the primary attribute for the entity

UI

  • Xrm.Page.ui.setFormNotification()
    • Takes in a string value to set a form notification with the passed in string
    • Pass in “ERROR”, “INFORMATION” or “WARNING” to dictate the type of notification

image 

  • Xrm.Page.ui.clearFormNotification()
    • Clears the form notification

All Controls

  • Xrm.Page.getControl("new_name").setNotification("Field specific notification")
    • Sets a notification specific to the field

image

  • Xrm.Page.getControl(“new_name”).clearNotification()
    • Clears the field specific notification

Number Fields

  • Xrm.Page.getAttribute("new_precision").setPrecision(2)
    • Override field’s precision

Date Fields

  • Xrm.Page.getControl("createdon").setShowTime(true)
    • Controls whether to show the time for a date field

Lookup Fields

  • Xrm.Page.getControl("ownerid").addCustomFilter(fetchFilter, entityType)
    • Applies a custom filter to the lookup view
    • entityType is optional and if it is not passed it will default to all entity views
  • Xrm.Page.getControl("ownerid").addPreSearch(handler)
    • triggers right before a lookup dialog pops open
  • Xrm.Page.getControl("ownerid").removePreSearch(handler)
    • removes event handler set from the addPreSearch method

Utility

  • Xrm.Utility.openWebResourceDialog(webResourceName, webResourceData, width, height)
    • opens a specified HTML web resource as a dialog

Comments

  1. Thanks for the article. It's worth pointing out that the 'openWebResourceDialog' has been postponed until a later release.
    There are also Xrm.Utility functions for alertDialog and confirmDialog that replace the window.alert and window.confirm methods so that these dialogs can be supported on a tablet/mobile device. Code that uses window.alert and window.confirm today will be mapped to the new functions, but in the future support for the window methods will be dropped making it important to start using the new methods.

    Posted by: Scott Durow  |  Sep 24, 2013 2:36:28 AM

  2. Thanks for the update Scott!

    Posted by: Blake Scarlavai  |  Sep 24, 2013 8:39:40 AM

  3. Thanks for the update. Do you know if they have an update of the XrmPage-vsdoc.js so we can have intellisense for these new functions?

    Posted by: Dustin Warner  |  Dec 10, 2013 8:24:54 AM

Post a Comment

  • *Required

Contact Us for a Quote, or Personalized Demonstrationof Microsoft Dynamics CRM for Your Business.

Contact Us