diff --git a/xrm/xrm.d.ts b/xrm/xrm.d.ts index a2f7c515b..1277b739c 100644 --- a/xrm/xrm.d.ts +++ b/xrm/xrm.d.ts @@ -1,9 +1,235 @@ -// Type definitions for Microsoft Dynamics xRM API v7.1 +// Compiled using typings@0.6.10 +// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/1209610bb338b0e50d15920c82d8f4e312faee26/xrm/xrm.d.ts +// Type definitions for Microsoft Dynamics xRM API v7.1 // Project: http://www.microsoft.com/en-us/download/details.aspx?id=44567 -// Definitions by: David Berry , Matt Ngan +// Definitions by: David Berry , Matt Ngan , Markus Mauch // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare module Xrm +/** + * Injects the Xrm object and GetGlobalContext function into the global namespace. + */ +declare var Xrm: XrmStatic; +declare function GetGlobalContext(): XrmInterface.Context; + +/** + * Extends the Window interface defined in lib.d.ts and makes the Xrm object and GetGlobalContext function accessible from any window object (window, parent, top, etc.). + */ +interface Window +{ + /** + * A reference to the xRM global object. + */ + Xrm: XrmStatic; + + /** + * Gets the xRM application context, for HTML web resources, included by ClientGlobalContext.js.aspx + * @returns {Xrm.Context} The application context for the user's current session. + * @remarks The ClientGlobalContext.js.aspx page will include some global event handlers. These event handlers will + * cancel the onselectstart, contextmenu, and ondragstart events. + */ + GetGlobalContext(): XrmInterface.Context; +} + +/** + * Static xRM object. + */ +interface XrmStatic +{ + /** + * Provides a namespace container for the context, data and ui objects. + */ + Page: { + /** + * Provides methods to retrieve information specific to an organization, a user, or parameters passed to a page. + */ + context: XrmInterface.Context; + + /** + * Provides methods to work with the form. + */ + data: XrmInterface.Data; + + /** + * Contains properties and methods to retrieve information about the user interface as well as collections for several subcomponents of the form. + */ + ui: XrmInterface.Ui; + + /** + * Gets all attributes. + * + * @return An array of attributes. + */ + getAttribute(): XrmInterface.Page.Attribute[]; + + /** + * Gets an attribute matching attributeName. + * + * @tparam T An Attribute type. + * @param {string} attributeName Name of the attribute. + * + * @return The attribute. + */ + getAttribute( attributeName: string ): T; + + /** + * Gets an attribute matching attributeName. + * + * @param {string} attributeName Name of the attribute. + * + * @return The attribute. + */ + getAttribute( attributeName: string ): XrmInterface.Page.Attribute; + + /** + * Gets an attribute by index. + * + * @param {number} index The attribute index. + * + * @return The attribute. + */ + getAttribute( index: number ): XrmInterface.Page.Attribute; + + /** + * Gets an attribute. + * + * @param {Collection.MatchingDelegate{Attribute}} delegateFunction A matching delegate function + * + * @return An array of attribute. + */ + getAttribute( delegateFunction: XrmInterface.Collection.MatchingDelegate ): XrmInterface.Page.Attribute[]; + + /** + * Gets all controls. + * + * @return An array of controls. + */ + getControl(): XrmInterface.Page.Control[]; + + /** + * Gets a control matching controlName. + * + * @tparam T A Control type + * @param {string} controlName Name of the control. + * + * @return The control. + */ + getControl( controlName: string ): T; + + /** + * Gets a control matching controlName. + * + * @param {string} controlName Name of the control. + * + * @return The control. + */ + getControl( controlName: string ): XrmInterface.Page.Control; + + /** + * Gets a control by index. + * + * @param {number} index The control index. + * + * @return The control. + */ + getControl( index: number ): XrmInterface.Page.Control; + + /** + * Gets a control. + * + * @param {Collection.MatchingDelegate{Control}} delegateFunction A matching delegate function. + * + * @return An array of control. + */ + getControl( delegateFunction: XrmInterface.Collection.MatchingDelegate ): XrmInterface.Page.Control[]; + } + + /** + * Provides a container for useful functions not directly related to the current page. + */ + Utility: { + /** + * Displays an alert dialog, with an "OK" button. + * + * @param {string} message The message. + * @param {function()} onCloseCallback The "OK" callback. + */ + alertDialog( message: string, onCloseCallback: () => void ): void; + + /** + * Displays a confirmation dialog, with "OK" and "Cancel" buttons. + * + * @param {string} message The message. + * @param {function()} yesCloseCallback The "OK" callback. + * @param {function()} noCloseCallback The "Cancel" callback. + */ + confirmDialog( message: string, yesCloseCallback: () => void, noCloseCallback: () => void ): void; + + /** + * Query if 'entityType' is an Activity entity. + * + * @param {string} entityType Type of the entity. + * + * @return true if the entity is an Activity, false if not. + */ + isActivityType( entityType: string ): boolean; + + /** + * Opens quick create. + * + * @param {Function} callback The function that will be called when a record is created. This + * function is passed a LookupValue object as a parameter. + * @param {string} entityLogicalName The logical name of the entity to create. + * @param {Page.LookupValue} createFromEntity (Optional) Designates a record that will provide default values + * based on mapped attribute values. + * @param {OpenParameters} parameters (Optional) A dictionary object that passes extra query string + * parameters to the form. Invalid query string parameters will cause an + * error. + */ + openQuickCreate( + callback: ( recordReference: XrmInterface.Page.LookupValue ) => void, + entityLogicalName: string, + createFromEntity?: XrmInterface.Page.LookupValue, + parameters?: XrmInterface.Utility.OpenParameters ): void; + + /** + * Opens an entity form. + * + * @param {string} name The entity's logical name. + * @param {string} id (Optional) The unique identifier for the record. + * @param {FormParameters} parameters (Optional) A dictionary object that passes extra query string parameters to the form. + * @param {WindowOptions} windowOptions (Optional) Options for controlling the window. + */ + openEntityForm( name: string, id?: string, parameters?: XrmInterface.Utility.FormOpenParameters, windowOptions?: XrmInterface.Utility.WindowOptions ): void; + + /** + * Opens an HTML Web Resource in a new browser window. + * + * @param {string} webResourceName Name of the HTML web resource. Can be used to pass URL + * parameters. See Remarks. + * @param {string} webResourceData (Optional) Data to pass into the Web Resource's data parameter. + * It is advised to use encodeURIcomponent() to encode the value. + * @param {number} width (Optional) The width of the new window. + * @param {number} height (Optional) The height of the new window. + * + * @return A Window reference, containing the opened Web Resource. + * + * @remarks This function will not work with Microsoft Dynamics CRM for tablets. + * Valid WebResource URL Parameters: typename + * type + * id + * orgname + * userlcid + * data (identical to this method's webResourceData parameter) + * formid + */ + openWebResource( webResourceName: string, webResourceData?: string, width?: number, height?: number ): Window; + } +} + +/** + * Ghost module for the Xrm interfaces. + */ +declare module XrmInterface { /** * Interface for the client context. @@ -139,6 +365,170 @@ declare module Xrm prependOrgName( sPath: string ): string; } + /** + * Interface for the Xrm.Page.data object. + */ + export interface Data + { + /** + * Asynchronously refreshes data on the form, without reloading the page. + * + * @param {boolean} save true to save the record, after the refresh. + * + * @return An Async.XrmPromise. + */ + refresh( save: boolean ): XrmInterface.Async.XrmPromise; + + /** + * Asynchronously saves the record. + * + * @return An Async.XrmPromise. + */ + save(): XrmInterface.Async.XrmPromise; + + /** + * The record context of the form. + */ + entity: XrmInterface.Page.Entity; + + /** + * The process API for Xrm.Page.data. + * + * @remarks This member may be undefined when Process Flows are not used by the current entity. + */ + process: XrmInterface.Page.data.ProcessManager; + } + + /** + * Interface for the Xrm.Page.ui object. + */ + export interface Ui + { + /** + * Clears the form notification described by uniqueId. + * + * @param {string} uniqueId Unique identifier. + * + * @return true if it succeeds, otherwise false. + */ + clearFormNotification( uniqueId: string ): boolean; + + /** + * Closes the form. + */ + close(): void; + + /** + * Gets form type. + * + * @return The form type. + * + * @remarks Values returned are: 0 Undefined + * 1 Create + * 2 Update + * 3 Read Only + * 4 Disabled + * 6 Bulk Edit + * Deprecated values are 5 (Quick Create), and 11 (Read Optimized) + */ + getFormType(): XrmInterface.Page.FormType; + + /** + * Gets view port height. + * + * @return The view port height, in pixels. + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + getViewPortHeight(): number; + + /** + * Gets view port width. + * + * @return The view port width, in pixels. + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + getViewPortWidth(): number; + + /** + * Re-evaluates the ribbon's configured EnableRules + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + refreshRibbon(): void; + + /** + * Sets a form-level notification. + * + * @param {string} message The message. + * @param {"ERROR"} level An error message. + * @param {string} uniqueId A unique identifier for the message. + * + * @return true if it succeeds, false if it fails. + */ + setFormNotification( message: string, level: "ERROR", uniqueId: string ): boolean; + + /** + * Sets a form-level notification. + * + * @param {string} message The message. + * @param {"WARNING"} level A warning message. + * @param {string} uniqueId A unique identifier for the message. + * + * @return true if it succeeds, false if it fails. + */ + setFormNotification( message: string, level: "WARNING", uniqueId: string ): boolean; + + /** + * Sets a form-level notification. + * + * @param {string} message The message. + * @param {"INFO"} level An informational message. + * @param {string} uniqueId A unique identifier for the message. + * + * @return true if it succeeds, false if it fails. + */ + setFormNotification( message: string, level: "INFO", uniqueId: string ): boolean; + + /** + * Sets a form-level notification. + * + * @param {string} message The message. + * @param {string} level The level, as either "ERROR", "WARNING", or "INFO". + * @param {string} uniqueId A unique identifier for the message. + * + * @return true if it succeeds, otherwise false. + */ + setFormNotification( message: string, level: string, uniqueId: string ): boolean; + + process: XrmInterface.Page.data.ProcessManager; + + /** + * A reference to the collection of controls on the form. + */ + controls: XrmInterface.Collection.ItemCollection; + + /** + * The form selector API. + * + * @remarks This API does not exist with Microsoft Dynamics CRM for tablets. + */ + formSelector: XrmInterface.Page.FormSelector; + + /** + * The navigation API. + * + * @remarks This API does not exist with Microsoft Dynamics CRM for tablets. + */ + navigation: XrmInterface.Page.Navigation; + + /** + * A reference to the collection of tabs on the form. + */ + tabs: XrmInterface.Collection.ItemCollection; + } + /** * A definition module for asynchronous interface declarations. */ @@ -486,7 +876,7 @@ declare module Xrm * * @return The event source. */ - getEventSource(): Xrm.Page.Attribute | Xrm.Page.Entity; + getEventSource(): XrmInterface.Page.Attribute | XrmInterface.Page.Entity; /** * Gets the shared variable with the specified key. @@ -1302,34 +1692,6 @@ declare module Xrm * Represents a key-value pair, where the key is the Process Flow's ID, and the value is the name thereof. */ export type ProcessDictionary = { [index: string]: string }; - - /** - * Asynchronously refreshes data on the form, without reloading the page. - * - * @param {boolean} save true to save the record, after the refresh. - * - * @return An Async.XrmPromise. - */ - export function refresh( save: boolean ): Async.XrmPromise; - - /** - * Asynchronously saves the record. - * - * @return An Async.XrmPromise. - */ - export function save(): Async.XrmPromise; - - /** - * The record context of the form. - */ - export var entity: Entity; - - /** - * The process API for Xrm.Page.data. - * - * @remarks This member may be undefined when Process Flows are not used by the current entity. - */ - export var process: ProcessManager; } /** @@ -1767,7 +2129,7 @@ declare module Xrm * * @return The parent. */ - getParent(): typeof ui; + getParent(): XrmInterface.Ui; /** * Sets display state of the tab. @@ -1996,130 +2358,6 @@ declare module Xrm */ getEntityReference(): LookupValue; } - - /** - * Clears the form notification described by uniqueId. - * - * @param {string} uniqueId Unique identifier. - * - * @return true if it succeeds, otherwise false. - */ - export function clearFormNotification( uniqueId: string ): boolean; - - /** - * Closes the form. - */ - export function close(): void; - - /** - * Gets form type. - * - * @return The form type. - * - * @remarks Values returned are: 0 Undefined - * 1 Create - * 2 Update - * 3 Read Only - * 4 Disabled - * 6 Bulk Edit - * Deprecated values are 5 (Quick Create), and 11 (Read Optimized) - */ - export function getFormType(): FormType; - - /** - * Gets view port height. - * - * @return The view port height, in pixels. - * - * @remarks This method does not work with Microsoft Dynamics CRM for tablets. - */ - export function getViewPortHeight(): number; - - /** - * Gets view port width. - * - * @return The view port width, in pixels. - * - * @remarks This method does not work with Microsoft Dynamics CRM for tablets. - */ - export function getViewPortWidth(): number; - - /** - * Re-evaluates the ribbon's configured EnableRules - * - * @remarks This method does not work with Microsoft Dynamics CRM for tablets. - */ - export function refreshRibbon(): void; - - /** - * Sets a form-level notification. - * - * @param {string} message The message. - * @param {"ERROR"} level An error message. - * @param {string} uniqueId A unique identifier for the message. - * - * @return true if it succeeds, false if it fails. - */ - export function setFormNotification( message: string, level: "ERROR", uniqueId: string ): boolean; - - /** - * Sets a form-level notification. - * - * @param {string} message The message. - * @param {"WARNING"} level A warning message. - * @param {string} uniqueId A unique identifier for the message. - * - * @return true if it succeeds, false if it fails. - */ - export function setFormNotification( message: string, level: "WARNING", uniqueId: string ): boolean; - - /** - * Sets a form-level notification. - * - * @param {string} message The message. - * @param {"INFO"} level An informational message. - * @param {string} uniqueId A unique identifier for the message. - * - * @return true if it succeeds, false if it fails. - */ - export function setFormNotification( message: string, level: "INFO", uniqueId: string ): boolean; - - /** - * Sets a form-level notification. - * - * @param {string} message The message. - * @param {string} level The level, as either "ERROR", "WARNING", or "INFO". - * @param {string} uniqueId A unique identifier for the message. - * - * @return true if it succeeds, otherwise false. - */ - export function setFormNotification( message: string, level: string, uniqueId: string ): boolean; - - export var process: ProcessManager; - - /** - * A reference to the collection of controls on the form. - */ - export var controls: Collection.ItemCollection; - - /** - * The form selector API. - * - * @remarks This API does not exist with Microsoft Dynamics CRM for tablets. - */ - export var formSelector: FormSelector; - - /** - * The navigation API. - * - * @remarks This API does not exist with Microsoft Dynamics CRM for tablets. - */ - export var navigation: Navigation; - - /** - * A reference to the collection of tabs on the form. - */ - export var tabs: Collection.ItemCollection; } /** @@ -2193,99 +2431,6 @@ declare module Xrm */ items: Collection.ItemCollection; } - - /** - * A reference to the xRM application context. - */ - export var context: Context; - - /** - * Gets all attributes. - * - * @return An array of attributes. - */ - export function getAttribute(): Attribute[]; - - /** - * Gets an attribute matching attributeName. - * - * @tparam T An Attribute type. - * @param {string} attributeName Name of the attribute. - * - * @return The attribute. - */ - export function getAttribute( attributeName: string ): T; - - /** - * Gets an attribute matching attributeName. - * - * @param {string} attributeName Name of the attribute. - * - * @return The attribute. - */ - export function getAttribute( attributeName: string ): Attribute; - - /** - * Gets an attribute by index. - * - * @param {number} index The attribute index. - * - * @return The attribute. - */ - export function getAttribute( index: number ): Attribute; - - /** - * Gets an attribute. - * - * @param {Collection.MatchingDelegate{Attribute}} delegateFunction A matching delegate function - * - * @return An array of attribute. - */ - export function getAttribute( delegateFunction: Collection.MatchingDelegate ): Attribute[]; - - /** - * Gets all controls. - * - * @return An array of controls. - */ - export function getControl(): Control[]; - - /** - * Gets a control matching controlName. - * - * @tparam T A Control type - * @param {string} controlName Name of the control. - * - * @return The control. - */ - export function getControl( controlName: string ): T; - - /** - * Gets a control matching controlName. - * - * @param {string} controlName Name of the control. - * - * @return The control. - */ - export function getControl( controlName: string ): Control; - - /** - * Gets a control by index. - * - * @param {number} index The control index. - * - * @return The control. - */ - export function getControl( index: number ): Control; - - /** - * Gets a control. - * - * @param {Collection.MatchingDelegate{Control}} delegateFunction A matching delegate function. - * - * @return An array of control. - */ - export function getControl( delegateFunction: Collection.MatchingDelegate ): Control[]; } /** @@ -2506,89 +2651,5 @@ declare module Xrm */ openInNewWindow: boolean; } - - /** - * Displays an alert dialog, with an "OK" button. - * - * @param {string} message The message. - * @param {function()} onCloseCallback The "OK" callback. - */ - export function alertDialog( message: string, onCloseCallback: () => void ): void; - - /** - * Displays a confirmation dialog, with "OK" and "Cancel" buttons. - * - * @param {string} message The message. - * @param {function()} yesCloseCallback The "OK" callback. - * @param {function()} noCloseCallback The "Cancel" callback. - */ - export function confirmDialog( message: string, yesCloseCallback: () => void, noCloseCallback: () => void ): void; - - /** - * Query if 'entityType' is an Activity entity. - * - * @param {string} entityType Type of the entity. - * - * @return true if the entity is an Activity, false if not. - */ - export function isActivityType( entityType: string ): boolean; - - /** - * Opens an entity form. - * - * @param {string} name The entity's logical name. - * @param {string} id (Optional) The unique identifier for the record. - * @param {FormParameters} parameters (Optional) A dictionary object that passes extra query string parameters to the form. - * @param {WindowOptions} windowOptions (Optional) Options for controlling the window. - */ - export function openEntityForm( name: string, id?: string, parameters?: FormOpenParameters, windowOptions?: WindowOptions ): void; - - /** - * Opens quick create. - * - * @param {Function} callback The function that will be called when a record is created. This - * function is passed a LookupValue object as a parameter. - * @param {string} entityLogicalName The logical name of the entity to create. - * @param {Page.LookupValue} createFromEntity (Optional) Designates a record that will provide default values - * based on mapped attribute values. - * @param {OpenParameters} parameters (Optional) A dictionary object that passes extra query string - * parameters to the form. Invalid query string parameters will cause an - * error. - */ - export function openQuickCreate( callback: ( recordReference: Page.LookupValue ) => void, - entityLogicalName: string, - createFromEntity?: Page.LookupValue, - parameters?: OpenParameters ): void; - - /** - * Opens an HTML Web Resource in a new browser window. - * - * @param {string} webResourceName Name of the HTML web resource. Can be used to pass URL - * parameters. See Remarks. - * @param {string} webResourceData (Optional) Data to pass into the Web Resource's data parameter. - * It is advised to use encodeURIcomponent() to encode the value. - * @param {number} width (Optional) The width of the new window. - * @param {number} height (Optional) The height of the new window. - * - * @return A Window reference, containing the opened Web Resource. - * - * @remarks This function will not work with Microsoft Dynamics CRM for tablets. - * Valid WebResource URL Parameters: typename - * type - * id - * orgname - * userlcid - * data (identical to this method's webResourceData parameter) - * formid - */ - export function openWebResource( webResourceName: string, webResourceData?: string, width?: number, height?: number ): Window; } } - -/** - * Gets the xRM application context, for HTML web resources, included by ClientGlobalContext.js.aspx - * @returns {Xrm.Context} The application context for the user's current session. - * @remarks The ClientGlobalContext.js.aspx page will include some global event handlers. These event handlers will - * cancel the onselectstart, contextmenu, and ondragstart events. - */ -declare function GetGlobalContext(): Xrm.Context;