Tuesday, 4 February 2014

New JavaScript methods in Microsoft Dynamics CRM 2013

 Microsoft Dynamics CRM 2013 is providing some exciting new methods we can use with the JavaScript SDK on the entity forms, such as :
  • Easier way to set the form dirty
  • Custom lookup filters
  • Displaying form notifications as well as field specific notifications. 
  • 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
  • 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
  • Xrm.Page.data.entity.getPrimaryAttributeValue()
    • Returns a string value of the primary attribute for the entity
  • 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
  • crm 2013
  • 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
  • crm 2013
  • 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
  • Xrm.Utility.openWebResourceDialog(webResourceName, webResourceData, width, height)
    • opens a specified HTML web resource as a dialog