Merge pull request #19752 from derekfinlinson/master

Add separate Process event context interfaces to xrm
This commit is contained in:
Benjamin Lichtman
2017-09-19 16:45:31 -07:00
committed by GitHub
2 changed files with 192 additions and 12 deletions

202
types/xrm/index.d.ts vendored
View File

@@ -893,7 +893,12 @@ declare namespace Xrm {
/**
* Status for Xrm.Page.Stage.getStatus().
*/
type Status = "active" | "inactive";
type StageStatus = "active" | "inactive";
/**
* Status for Xrm.Page.Process.getStatus().
*/
type ProcessStatus = "active" | "aborted" | "finished";
/**
* Submit Mode for Xrm.Page.Attribute.getSubmitMode() and Xrm.Page.Attribute.setSubmitMode().
@@ -935,6 +940,11 @@ declare namespace Xrm {
*/
type AttributeType = "boolean" | "datetime" | "decimal" | "double" | "integer" | "lookup" | "memo" | "money" | "optionset" | "string";
/**
* Direction types for a process stage change event
*/
type StageChangeDirection = "Next" | "Previous";
/**
* Attribute formats for Xrm.Page.Attribute.getFormat().
*/
@@ -1017,7 +1027,7 @@ declare namespace Xrm {
*
* @remarks This method will return either "active" or "inactive".
*/
getStatus(): Status;
getStatus(): StageStatus;
/**
* Returns a collection of steps in the stage.
@@ -1074,15 +1084,6 @@ declare namespace Xrm {
*/
getDepth(): number;
/**
* Gets save-event arguments.
*
* @return The event arguments.
*
* @remarks Returns null for all but the "save" event.
*/
getEventArgs(): SaveEventArguments;
/**
* Gets a reference to the object for which event occurred.
*
@@ -1114,12 +1115,55 @@ declare namespace Xrm {
setSharedVariable<T>(key: string, value: T): void;
}
/**
* Interface for a save event context
*/
interface SaveEventContext extends EventContext {
/**
* Gets save-event arguments.
*
* @return The event arguments.
*
* @remarks Returns null for all but the "save" event.
*/
getEventArgs(): SaveEventArguments;
}
/**
* Interface for a process stage change event context
*/
interface StageChangeEventContext extends EventContext {
/**
* Gets process stage change event arguments.
*
* @return The event arguments.
*
*/
getEventArgs(): StageChangeEventArguments;
}
interface StageSelectedEventContext extends EventContext {
/**
* Gets process stage selected event arguments.
*
* @return The event arguments.
*
*/
getEventArgs(): StageSelectedEventArguments;
}
/**
* Type for a context-sensitive handler.
* @param {EventContext} context The context.
*/
type ContextSensitiveHandler = (context: EventContext) => void;
/**
* Type for a process status change handler.
* @param {ProcessStatus} status The process status.
*/
type ProcessStatusChangeHandler = (status: ProcessStatus) => void;
/**
* Interface for UI elements with labels.
*/
@@ -1916,6 +1960,41 @@ declare namespace Xrm {
preventDefault(): void;
}
/**
* Interface for process stage change event arguments.
*/
interface StageChangeEventArguments {
/**
* Gets the direction of the stage change.
*
* @return The direction.
*
* @remarks Values returned are: "next" or "previous"
*/
getDirection(): StageChangeDirection;
/**
* Gets the destination stage object
*
* @return The stage object
*
* @remarks For switching between entities, returns the previous stage object
*/
getStage(): Stage;
}
/**
* Interface for process stage selected event arguments.
*/
interface StageSelectedEventArguments {
/**
* Gets the selected stage object
*
* @return The stage object
*/
getStage(): Stage;
}
/**
* Module for the Xrm.Page.data API.
*/
@@ -1939,6 +2018,21 @@ declare namespace Xrm {
*/
setActiveProcess(processId: string, callbackFunction?: ProcessCallbackDelegate): void;
/**
* Returns all process instances for the entity record that the calling user has access to.
*
* @param {function} callbackFunction (Optional) a function to call when the operation is complete.
*/
getProcessInstances(callbackFunction: GetProcessInstancesDelegate): void;
/**
* Sets a process instance as the active instance
*
* @param {string} processInstanceId The Id of the process instance to make the active instance.
* @param {function} callbackFunction (Optional) a function to call when the operation is complete.
*/
setActiveProcessInstance(processInstanceId: string, callbackFunction: SetProcessInstanceDelegate): void;
/**
* Returns a Stage object representing the active stage.
*
@@ -2001,6 +2095,19 @@ declare namespace Xrm {
*/
addOnStageChange(handler: ContextSensitiveHandler): void;
/**
* Use this to add a function as an event handler for the OnProcessStatusChange event so that it will be called when the
* business process flow status changes.
* @param {ProcessStatusChangeHandler} handler The function will be added to the bottom of the event
* handler pipeline. The execution context is automatically
* set to be the first parameter passed to the event handler.
*
* Use a reference to a named function rather than an
* anonymous function if you may later want to remove the
* event handler.
*/
addOnProcessStatusChange(handler: ProcessStatusChangeHandler): void;
/**
* Use this to add a function as an event handler for the OnStageSelected event so that it will be called
* when a business process flow stage is selected.
@@ -2015,6 +2122,14 @@ declare namespace Xrm {
*/
addOnStageSelected(handler: ContextSensitiveHandler): void;
/**
* Use this to remove a function as an event handler for the OnProcessStatusChange event.
*
* @param {ProcessStatusChangeHandler} handler If an anonymous function is set using the addOnProcessStatusChange method it
* cannot be removed using this method.
*/
removeOnProcessStatusChange(handler: ProcessStatusChangeHandler): void;
/**
* Use this to remove a function as an event handler for the OnStageChange event.
*
@@ -2046,8 +2161,62 @@ declare namespace Xrm {
* complete.
*/
movePrevious(callbackFunction?: ProcessCallbackDelegate): void;
/**
* Use this method to get the unique identifier of the process instance
*
* @return The unique identifier of the process instance
*/
getInstanceId(): string;
/**
* Use this method to get the name of the process instance
*
* @return The name of the process instance
*/
getInstanceName(): string;
/**
* Use this method to get the current status of the process instance
*
* @return The current status of the process
*/
getStatus(): ProcessStatus;
/**
* Use this method to set the current status of the process instance
*
* @param {ProcessStatus} status The new status for the process
* @param {function} callbackFunction (Optional) a function to call when the operation is complete.
*/
setStatus(status: ProcessStatus, callbackFunction: ProcessSetStatusDelegate): void;
}
/**
* Called when method to get active processes is complete
*
* @param {string} status The result of the get active processes operation.
*
* @remarks Returns object with the following key-value pairs:
* CreatedOn
* ProcessDefinitionID
* ProcessDefinitionName
* ProcessInstanceID
* ProcessInstanceName
* StatusCodeName
*/
type GetProcessInstancesDelegate = (object: ProcessDictionary) => void;
/**
* Called when method to set active process is complete
*
* @param {string} status The result of the set active process operation.
*
* @remarks Values returned are: success (The operation succeeded.)
* invalid (The processInstanceId isnt valid or the process isnt enabled.)
*/
type SetProcessInstanceDelegate = (status: string) => void;
/**
* Called when process change methods have completed.
*
@@ -2062,6 +2231,17 @@ declare namespace Xrm {
*/
type ProcessCallbackDelegate = (status: string) => void;
/**
* Called when process set status method has completed.
*
* @param {ProcessStatus} status The new status of the process instance
*
* @remarks Values returned are: active
* aborted
* finished
*/
type ProcessSetStatusDelegate = (status: ProcessStatus) => void;
/**
* Represents a key-value pair, where the key is the Process Flow's ID, and the value is the name thereof.
*/

View File

@@ -83,7 +83,7 @@ Xrm.Page.ui.tabs.forEach((tab) => {
/// Demonstrate OnSave event context.
Xrm.Page.data.entity.addOnSave((context) => {
Xrm.Page.data.entity.addOnSave((context: Xrm.Page.SaveEventContext) => {
const eventArgs = context.getEventArgs();
if (eventArgs.getSaveMode() === XrmEnum.SaveMode.AutoSave || eventArgs.getSaveMode() === XrmEnum.SaveMode.SaveAndClose)