OnLoad event for SubGrid in CRM 2015 Update 1

Till CRM 2011 we used to use Xrm.page.getControl(“grid”) to get a grid control available on form and perform any runtime activity like changing the view/query, etc. Also we were required to write the complete script on OnLoad even of form and add a timeout till the subgrid is loaded as subgrids are loaded asynchronously after the form is loaded. There was no way we can have a trigger on load of a subgrid till CRM 2015 Update 1. What we used to do is explained in older post here.

But with CRM 2015 update 1, we now have an option to execute scripts when data is loaded in subgrids. Because of which we are not required to have any timeout added in the script and iterate it till the data is loaded into subgrid.

With addition on GridControl.addOnLoad method, we can now add event handler for OnLoad event of subgrid which is more reliable than the form OnLoad event for form with a timeout. This event will get triggered whenever data is bound to a subgrid.

The steps to add this event is not similar to adding a form OnLoad event (from form customization popup), the way to add it is by invoking it using a code from other events (e.g. form OnLoad) by making use of GridControl.addOnLoad method. Similarly, use GridControl.removeOnLoad to remove event handlers.

Xrm.Page.getControl(“Contacts”).addOnLoad(myContactsGridOnloadFunction);

References:

https://msdn.microsoft.com/en-us/library/dn932137.aspx?f=255&MSPPError=-2147217396

https://msdn.microsoft.com/en-us/library/dn932126.aspx#BKMK_subgridAddOnLoad

https://crmcooking.wordpress.com/2015/07/15/writing-scripts-for-subgrids-with-crm-2015-update-1/

DID YOU KNOW? You can update owner and status with a single Update request in CRM 2015 with Update 1

Before CRM 2015 Update 1 release, specialized messages were required to update certain entity attribute values. These were AssignRequest to change owner of a record, SetStateRequest to change status of a record, SetParentSystemUserRequest, etc. In this release, UpdateRequest can now be used to set these attributes.

Thus with Update 1 release following specialized message will be deprecated.

  1. AssignRequest
  2. SetStateRequest
  3. SetParentSystemUserRequest
  4. SetParentTeamRequest
  5. SetParentBusinessUnitRequest
  6. SetBusinessUnitRequest
  7. SetBusinessEquipmentRequest
  8. SetBusinessSystemUserRequest

These specialized messages will continue to work with the 2011 endpoint. However, the recommendation is to use the UpdateRequest or Update method when possible to set these attributes. The Update message simplifies the SDK API and makes it easier to code standard data integration tools used with Dynamics CRM. In addition, it is easier to code and register a plug-in to execute for a single Update message instead of multiple specialized messages. The AttributeMetadata.IsValidForUpdate property for the above listed attributes has been changed to true in this release to enable this capability.

For plug-ins, when update requests are processed that include both owner fields plus other standard fields for business owned entities, plug-ins registered for the Update message in pipeline stage 20 and/or stage 40 execute once for all non-owner fields, and then once for the owner fields.

For workflows, when update requests are processed that include both owner fields plus other standard fields, workflows registered for the Update message execute once for all non-owner fields, and then once for the owner fields. Workflows registered for the Assign message by users continue to be triggered by updates to owner fields. When update requests are processed that include both state/status fields plus other standard fields, workflows registered for the Update message execute once for all non-state/status fields, and then once for the state/status fields. Workflows registered for the Change Status step continue to be triggered by updates to state/status fields.

CRM 2015 Update 1: Store date and time values with or without time zone information

Until the previous release of CRM, all date and time values in CRM were time zone aware, including those with the Date Only format.

Use the new DateTimeAttributeMetadata.DateTimeBehavior property to store date and time values with or without time zone information. Until now, all the date and time values in CRM were stored using the user’s local time zone information, including those with the DateOnly format. The CRM system use to convert values from the user’s local time zone to Coordinated Universal Time (UTC) on update, and back to the current user’s time zone when displayed on the form.

This was not an optimal experience for storing and using:

  • Date only values without the time information, such as birthdays and anniversaries.
  • Date and time values without the time zone information so that users across multiple time zones see the same date and time value, such as the hotel check-in time.

You can use the DateTimeBehavior enumeration to specify a value for the DateTimeBehavior property, or can directly specify the string value. The DateTimeBehavior property can have any of the following three values:

The following sample code demonstrates how to set a DateOnly behavior for a new attribute:

// Create a date time attribute

DateTimeAttributeMetadata dtAttribute = new DateTimeAttributeMetadata

{

// Set base properties

SchemaName = “new_Birthday”,

DisplayName = new Label(“Birthday”, _1033),

Description = new Label(“Birthday”, 1033),

DateTimeBehavior = DateTimeBehavior.DateOnly

Format = DateTimeFormat.DateOnly,

ImeMode = ImeMode.Disabled

};

 

In the above code, you can also set the value of the DateTimeBehavior property by directly specifying the string value: DateTimeBehavior = “DateOnly”

Use the DateTimeAttributeMetadata.Format property to specify the date/time display format of the attribute irrespective of how it is stored in the database. You can use the DateTimeFormat enumeration to specify the display format: DateAndTime or DateOnly.

If the DateTimeBehavior property is set to DateOnly, you cannot set or change the value of the Format property to DateAndTime.

 

***Reference: https://msdn.microsoft.com/en-us/library/89969adc-8577-424c-bfcc-7f65c5d4bd19#BKMK_DateTimeAttrbuteMetadata

***Important: This topic is pre-release documentation and is subject to change in future releases.