From 348824ec702d040c2b44c8da3ae528fe4533b1d3 Mon Sep 17 00:00:00 2001 From: Daryl LaBar Date: Fri, 5 May 2017 10:18:35 -0400 Subject: [PATCH 1/5] Updated XrmStatic Properties Page, Utility, and Panel to match the pattern that Mobil was doing, and be defined as interfaces. This also makes allows for variables to easily be tyepd i.e. var p: Xrm.Page. Also retyped getInitalValue for booleans and OptionsetValues to be their correct respective types. --- types/xrm/index.d.ts | 423 +++++++++++++++++++++++-------------------- 1 file changed, 224 insertions(+), 199 deletions(-) diff --git a/types/xrm/index.d.ts b/types/xrm/index.d.ts index 956dc969a2..27029961bd 100644 --- a/types/xrm/index.d.ts +++ b/types/xrm/index.d.ts @@ -24,198 +24,12 @@ declare namespace Xrm { /** * 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: Context; - - /** - * Provides methods to work with the form. - */ - data: Data; - - /** - * Contains properties and methods to retrieve information about the user interface as well as collections for several subcomponents of the form. - */ - ui: Ui; - - /** - * Gets all attributes. - * - * @return An array of attributes. - */ - getAttribute(): 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): Page.Attribute; - - /** - * Gets an attribute by index. - * - * @param {number} index The attribute index. - * - * @return The attribute. - */ - getAttribute(index: number): Page.Attribute; - - /** - * Gets an attribute. - * - * @param {Collection.MatchingDelegate{Attribute}} delegateFunction A matching delegate function - * - * @return An array of attribute. - */ - getAttribute(delegateFunction: Collection.MatchingDelegate): Page.Attribute[]; - - /** - * Gets all controls. - * - * @return An array of controls. - */ - getControl(): 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): Page.Control; - - /** - * Gets a control by index. - * - * @tparam T A Control type - * @param {number} index The control index. - * - * @return The control. - */ - getControl(index: number): T; - - /** - * Gets a control by index. - * - * @param {number} index The control index. - * - * @return The control. - */ - getControl(index: number): Page.Control; - - /** - * Gets a control. - * - * @param {Collection.MatchingDelegate{Control}} delegateFunction A matching delegate function. - * - * @return An array of control. - */ - getControl(delegateFunction: Collection.MatchingDelegate): Page.Control[]; - }; + Page: Page; /** * 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 {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. - * @return {Async.XrmPromise} Returns an asynchronous promise. - */ - openQuickCreate(entityLogicalName: string, createFromEntity?: Page.LookupValue, parameters?: Utility.OpenParameters): - Async.XrmPromise; - - /** - * 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?: Utility.FormOpenParameters, windowOptions?: 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; - }; + Utility: Utility; /** * Provides methods to create and manage records in the mobile clients (for phones tablets). @@ -227,17 +41,7 @@ declare namespace Xrm { * * @see {@link https://msdn.microsoft.com/en-us/library/mt790281.aspx} for details. */ - Panel: { - /** - * Displays the web page represented by a URL in the static area in the side pane, which appears on all pages in the web client. - * - * @param {string} url URL of the page to be loaded in the side pane static area. - * @param {string} url Title of the side pane static area. - * - * @remarks This method is only supported for the web client. - */ - LoadPanel(url: string, title: string): void; - }; + Panel: Panel; } /** @@ -443,6 +247,122 @@ declare namespace Xrm { process: Page.data.ProcessManager; } + interface Page { + /** + * Provides methods to retrieve information specific to an organization, a user, or parameters passed to a page. + */ + context: Context; + + /** + * Provides methods to work with the form. + */ + data: Data; + + /** + * Contains properties and methods to retrieve information about the user interface as well as collections for several subcomponents of the form. + */ + ui: Ui; + + /** + * Gets all attributes. + * + * @return An array of attributes. + */ + getAttribute(): 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): Page.Attribute; + + /** + * Gets an attribute by index. + * + * @param {number} index The attribute index. + * + * @return The attribute. + */ + getAttribute(index: number): Page.Attribute; + + /** + * Gets an attribute. + * + * @param {Collection.MatchingDelegate{Attribute}} delegateFunction A matching delegate function + * + * @return An array of attribute. + */ + getAttribute(delegateFunction: Collection.MatchingDelegate): Page.Attribute[]; + + /** + * Gets all controls. + * + * @return An array of controls. + */ + getControl(): 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): Page.Control; + + /** + * Gets a control by index. + * + * @tparam T A Control type + * @param {number} index The control index. + * + * @return The control. + */ + getControl(index: number): T; + + /** + * Gets a control by index. + * + * @param {number} index The control index. + * + * @return The control. + */ + getControl(index: number): Page.Control; + + /** + * Gets a control. + * + * @param {Collection.MatchingDelegate{Control}} delegateFunction A matching delegate function. + * + * @return An array of control. + */ + getControl(delegateFunction: Collection.MatchingDelegate): Page.Control[]; + + } + /** * Interface for the Xrm.Page.ui object. */ @@ -552,6 +472,81 @@ declare namespace Xrm { quickForms: Collection.ItemCollection; } + export interface 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 {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. + * @return {Async.XrmPromise} Returns an asynchronous promise. + */ + openQuickCreate(entityLogicalName: string, createFromEntity?: Page.LookupValue, parameters?: Utility.OpenParameters): + Async.XrmPromise; + + /** + * 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?: Utility.FormOpenParameters, windowOptions?: 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; + } + /** * Interface for methods to create and manage records in the mobile clients (for phones tablets). */ @@ -666,6 +661,18 @@ declare namespace Xrm { deleteRecord(entityType: string, id: string): Async.XrmPromise; } + export interface Panel { + /** + * Displays the web page represented by a URL in the static area in the side pane, which appears on all pages in the web client. + * + * @param {string} url URL of the page to be loaded in the side pane static area. + * @param {string} url Title of the side pane static area. + * + * @remarks This method is only supported for the web client. + */ + LoadPanel(url: string, title: string): void; + } + /** * A definition module for asynchronous interface declarations. */ @@ -1595,6 +1602,15 @@ declare namespace Xrm { * @sa EnumAttribute */ interface BooleanAttribute extends EnumAttribute { + /** + * Gets the initial value of the attribute. + * + * @return The initial value. + * + * @remarks Valid for OptionSet and boolean attribute types + */ + getInitialValue(): boolean; + /** * Gets the value. * @@ -1666,6 +1682,15 @@ declare namespace Xrm { */ getFormat(): OptionSetAttributeFormat; + /** + * Gets the initial value of the attribute. + * + * @return The initial value. + * + * @remarks Valid for OptionSet and boolean attribute types + */ + getInitialValue(): number; + /** * Gets the option matching a value. * From a863ce1cce555f312f65a1c1e7f00e4d21e642b5 Mon Sep 17 00:00:00 2001 From: Daryl LaBar Date: Fri, 5 May 2017 11:28:08 -0400 Subject: [PATCH 2/5] Fixed Linitng issues and fixed header so it could be parsed by the DT Bot --- types/xrm/index.d.ts | 11 +++-------- types/xrm/xrm-tests.ts | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/types/xrm/index.d.ts b/types/xrm/index.d.ts index 27029961bd..81d35cfe9b 100644 --- a/types/xrm/index.d.ts +++ b/types/xrm/index.d.ts @@ -1,10 +1,6 @@ // Type definitions for Microsoft Dynamics xRM API 8.2 // Project: http://www.microsoft.com/en-us/download/details.aspx?id=44567 -// Definitions by: David Berry -// Matt Ngan -// Markus Mauch -// Daryl LaBar -// Tully H +// Definitions by: David Berry , Matt Ngan , Markus Mauch , Daryl LaBar , Tully H // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 @@ -360,7 +356,6 @@ declare namespace Xrm { * @return An array of control. */ getControl(delegateFunction: Collection.MatchingDelegate): Page.Control[]; - } /** @@ -472,7 +467,7 @@ declare namespace Xrm { quickForms: Collection.ItemCollection; } - export interface Utility { + interface Utility { /** * Displays an alert dialog, with an "OK" button. * @@ -661,7 +656,7 @@ declare namespace Xrm { deleteRecord(entityType: string, id: string): Async.XrmPromise; } - export interface Panel { + interface Panel { /** * Displays the web page represented by a URL in the static area in the side pane, which appears on all pages in the web client. * diff --git a/types/xrm/xrm-tests.ts b/types/xrm/xrm-tests.ts index 5d9d99b644..5b5b12c333 100644 --- a/types/xrm/xrm-tests.ts +++ b/types/xrm/xrm-tests.ts @@ -143,7 +143,7 @@ const resultSet: Xrm.Page.AutoCompleteResultSet = { // accounts in CRM. window.open("http://www.microsoft.com/en-us/dynamics/crm-customer-center/create-or-edit-an-account.aspx"); } - } as Xrm.Page.AutoCompleteCommand + } }; resultSet.results.push({ id: 0, From d9052e486600818de742c51766747d327428764a Mon Sep 17 00:00:00 2001 From: Daryl LaBar Date: Fri, 5 May 2017 13:59:31 -0400 Subject: [PATCH 3/5] Fixed Other Lint-ing Issues. Not sure what to do about the header being unparsable. Added commas, maybe that will help? --- types/xrm/index.d.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/types/xrm/index.d.ts b/types/xrm/index.d.ts index 81d35cfe9b..6e6a1d5117 100644 --- a/types/xrm/index.d.ts +++ b/types/xrm/index.d.ts @@ -1,6 +1,10 @@ // Type definitions for Microsoft Dynamics xRM API 8.2 // Project: http://www.microsoft.com/en-us/download/details.aspx?id=44567 -// Definitions by: David Berry , Matt Ngan , Markus Mauch , Daryl LaBar , Tully H +// Definitions by: David Berry , +// Matt Ngan , +// Markus Mauch , +// Daryl LaBar , +// Tully H // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 @@ -656,7 +660,7 @@ declare namespace Xrm { deleteRecord(entityType: string, id: string): Async.XrmPromise; } - interface Panel { + interface Panel { /** * Displays the web page represented by a URL in the static area in the side pane, which appears on all pages in the web client. * From 597b4debe83f4bdc6752f7c9a9d58456e9fe1aea Mon Sep 17 00:00:00 2001 From: Daryl LaBar Date: Mon, 15 May 2017 11:05:23 -0400 Subject: [PATCH 4/5] Fix for @types/xrm missing context.getVersion #16528. Also fixed TD bot parsing of Definitions by making one line, and updating TsLint to allow for the long line. --- types/xrm/index.d.ts | 7 +++++++ types/xrm/tslint.json | 1 + 2 files changed, 8 insertions(+) diff --git a/types/xrm/index.d.ts b/types/xrm/index.d.ts index 6e6a1d5117..f09765442b 100644 --- a/types/xrm/index.d.ts +++ b/types/xrm/index.d.ts @@ -180,6 +180,13 @@ declare namespace Xrm { */ getUserRoles(): string[]; + /** + * Returns the version number of the Dynamics 365 server. + * + * @return The version number + */ + getVersion(): string; + /** * Prefixes the current organization's unique name to a string; typically a URL path. * diff --git a/types/xrm/tslint.json b/types/xrm/tslint.json index 380672b073..29835e4ef0 100644 --- a/types/xrm/tslint.json +++ b/types/xrm/tslint.json @@ -8,6 +8,7 @@ true, "spaces" ], + "max-line-length": [true, 250], "quotemark": [ true, "double" From cc734ec96062496cf09edcf3c09406edd1567e41 Mon Sep 17 00:00:00 2001 From: Daryl LaBar Date: Mon, 15 May 2017 11:05:54 -0400 Subject: [PATCH 5/5] Moved to one line. --- types/xrm/index.d.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/types/xrm/index.d.ts b/types/xrm/index.d.ts index f09765442b..56239ba907 100644 --- a/types/xrm/index.d.ts +++ b/types/xrm/index.d.ts @@ -1,10 +1,6 @@ // Type definitions for Microsoft Dynamics xRM API 8.2 // Project: http://www.microsoft.com/en-us/download/details.aspx?id=44567 -// Definitions by: David Berry , -// Matt Ngan , -// Markus Mauch , -// Daryl LaBar , -// Tully H +// Definitions by: David Berry , Matt Ngan , Markus Mauch , Daryl LaBar , Tully H // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1