共用方式為


Execution context (client-side reference)

 

Applies To: Dynamics CRM 2013

The execution context is an optional parameter that can be passed to a JavaScript library function through an event handler. This option is presented in the handler properties dialog when you specify the name of the function. This option is set for a <Handler> (FormXml) element using the passExecutionContext attribute.

Execution context is automatically passed to functions set using the Xrm.Page.data.addOnSave and Xrm.Page.data.entity Attribute.addOnChange, and Xrm.Page.ui Control.addPreSearch methods.

Execution Context Methods

  • getContext
    Method that returns the Client-side context (client-side reference) object.

  • getDepth
    Method that returns a value that indicates the order in which this handler is executed.

  • getEventArgs
    Method that returns an object with methods to manage the Save event.

  • getEventSource
    Method that returns a reference to the object that the event occurred on.

  • Shared Variables
    Shared variables allow sharing of a variable with other handlers for the same event. You use the setSharedVariable and getSharedVariable methods to work with shared variables.

getContext

Method that returns the Client-side context (client-side reference) object

ExecutionContextObj.getContext()
  • Return Value
    Type: Object

getDepth

Method that returns a value that indicates the order in which this handler is executed.

  • Return Value
    Type: Number

    The order begins with 0.

getEventArgs

Method that returns an object with methods to manage the Save event.

Note

This method returns null for any event other than the Save event.

ExecutionContextObj.getEventArgs()

getEventSource

Method that returns a reference to the object that the event occurred on.

ExecutionContextObj.getEventSource()
  • Return Value
    Type: Object

    This method returns the object from the Xrm.Page object model that is the source of the event, not an HTML DOM object. For example, in an OnChange event, this method returns the Xrm.Page.data.entity Attribute object that represents the changed attribute.

Shared Variables

Shared variables allow sharing of a variable with other handlers for the same event. You use the setSharedVariable and getSharedVariable methods to pass variables between functions.

setSharedVariable

Sets the value of a variable to be used by a handler after the current handler completes.

ExecutionContextObj.setSharedVariable(key, value)
  • Arguments
    String: The name of the variable

    Object: The value to set.

getSharedVariable

Retrieves a variable set using setSharedVariable.

ExecutionContextObj.getSharedVariable(key)
  • Arguments
    String: The name of the variable.

  • Return Value
    Type: Object

    The specific type depends on what the value object is.