From 28634dc8849bbdf61ef0a8de2e2a29fa0ebea6f6 Mon Sep 17 00:00:00 2001 From: clownwilleatme Date: Tue, 7 Feb 2017 10:19:05 +1100 Subject: [PATCH 1/9] Adding XRM v8.2 features --- xrm/index.d.ts | 838 +++++++++++++++++++++++++++++++++++++++-------- xrm/xrm-tests.ts | 27 +- 2 files changed, 736 insertions(+), 129 deletions(-) diff --git a/xrm/index.d.ts b/xrm/index.d.ts index 36bd556c13..2ed4cef363 100644 --- a/xrm/index.d.ts +++ b/xrm/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for Microsoft Dynamics xRM API v8.0 +// Type definitions for Microsoft Dynamics xRM API v8.2 // Project: http://www.microsoft.com/en-us/download/details.aspx?id=44567 -// Definitions by: David Berry , Matt Ngan , Markus Mauch , Daryl LaBar +// Definitions by: David Berry , Matt Ngan , Markus Mauch , Daryl LaBar , Tully H // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare var Xrm: Xrm.XrmStatic; @@ -93,7 +93,7 @@ declare namespace Xrm * Gets a control matching controlName. * * @tparam T A Control type - * @param {string} controlName Name of the control. + * @param {string} controlName Name of the control. * * @return The control. */ @@ -102,12 +102,22 @@ declare namespace Xrm /** * Gets a control matching controlName. * - * @param {string} controlName Name of the control. + * @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. * @@ -166,11 +176,10 @@ declare namespace Xrm * @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; + openQuickCreate( entityLogicalName: string, createFromEntity?: Page.LookupValue, parameters?: Utility.OpenParameters ): + Async.XrmPromise; /** * Opens an entity form. @@ -205,16 +214,194 @@ declare namespace Xrm */ openWebResource( webResourceName: string, webResourceData?: string, width?: number, height?: number ): Window; } + + /** + * Provides methods to create and manage records in the mobile clients (for phones tablets). + */ + Mobile: { + /** + * Provides methods to create and manage records in the mobile clients while working in the offline mode. + * + * @see {@link https://msdn.microsoft.com/en-us/library/mt787123.aspx} for details. + */ + offline: { + /** + * Returns whether an entity is offline enabled. + * + * @param {string} entityType The logical name of the entity. + * + * @return {boolean} True if the entity is offline enabled; otherwise False. + */ + isOfflineEnabled( entityType: string ): boolean; + + /** + * Creates an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {Object} data A dictionary object containing key : value pairs for the record to create. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot create intersect and activity party entities. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + createRecord( entityType: string, data: { [attributeName: string]: any } ): Async.XrmPromise; + + /** + * Retrieves an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to retrieve. + * @param {string} options (Optional) OData system query options to retrieve your data. Supports $select and $expand + * Example: ?$select=name&$expand=primarycontactid($select=contactid,fullname) + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks Only $select option can be specified within $expand. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + retrieveRecord( entityType: string, id: string, options: string ): Async.XrmPromise; + + /** + * Retrieves a collection of entity records in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} options (Optional) The logical name of the enti + * @param {string} maxPageSize (Optional) A positive number to indicates the number of entity records to be returned per page. + * If you do not specify this parameter, the default value is passed as 5000. + * If the number of records being retrieved is more than maxPageSize, an @odata.nextLink property + * will be returned, and you can use the value of the @odata.nextLink property with a new GET + * request to return next set of records. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks A maximum of 5000 related records can be retrieved when using $expand. + * Only $select option can be specified within $expand. + * $skip query option is not supported. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + retrieveMultipleRecords( entityType: string, options: string, maxPageSize: number ): Async.XrmPromise; + + /** + * Updates an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to update. + * @param {Object} data A dictionary object containing key : value pairs for the record to update. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot update intersect and activity party entities. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + updateRecord( entityType: string, id: string, data: { [attributeName: string]: any } ): Async.XrmPromise; + + /** + * Deletes an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to delete. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot delete intersect and activity party entities. + */ + deleteRecord( entityType: string, id: string ): Async.XrmPromise; + } + } + + /** + * Provides methods to display a web page in the side pane of web client. + * + * @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; + } } /** * Client Types for Xrm.Page.context.getClient(). */ export type Client = "Web" | "Outlook" | "Mobile"; + /** * Client States for Xrm.Page.context.getClientState(). */ export type ClientState = "Online" | "Offline"; + /** * Themes for Xrm.Page.context.getCurrentTheme(). */ @@ -254,6 +441,7 @@ declare namespace Xrm * Gets client's base URL for Dynamics CRM * * @return The client's base URL + * * @remarks For Dynamics CRM On-Premises: http(s)://server/org * For Dynamics CRM Online: https://org.crm.dynamics.com * For Dynamics CRM for Outlook (Offline): http://localhost:2525 @@ -354,6 +542,20 @@ declare namespace Xrm prependOrgName( sPath: string ): string; } + /** + * Defines save options to control how appointment, recurring appointment, or service activity records are processed. + * + * @see {@link https://msdn.microsoft.com/en-us/library/dn481607.aspx#Anchor_2} for details. + */ + interface SaveOptions + { + /** + * Indicates whether to use the Book or Reschedule messages rather than the Create or Update messages. + * Applicable to appointment, recurring appointment, or service activity records. + */ + UseSchedulingEngine?: boolean; + } + /** * Interface for the Xrm.Page.data object. */ @@ -364,16 +566,25 @@ declare namespace Xrm * * @param {boolean} save true to save the record, after the refresh. * - * @return An Async.XrmPromise. + * @return {Async.XrmPromise} Returns an asynchronous promise. */ - refresh( save: boolean ): Async.XrmPromise; + refresh( save: boolean ): Async.XrmPromise; /** * Asynchronously saves the record. * - * @return An Async.XrmPromise. + * @return {Async.XrmPromise} Returns an asynchronous promise. */ - save(): Async.XrmPromise; + save(): Async.XrmPromise; + + /** + * Asynchronously saves the record with the option to set callback functions to be executed after the save operation is completed. + * + * @param {saveOptions} saveOptions Options to control how appointment, recurring appointment, or service activity records are processed. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + */ + save( saveOptions: SaveOptions ): Async.XrmPromise; /** * The record context of the form. @@ -393,12 +604,28 @@ declare namespace Xrm */ export interface Ui { + /** + * Displays a form level notification. Any number of notifications can be displayed and will remain until removed using clearFormNotification. + * The height of the notification area is limited so each new message will be added to the top. + * + * @param {string} message The text of the notification message. + * @param {Page.ui.FormNotificationLevel} level The level of the notification which defines how the message will be displayed, such as the icon. + * @param {string} uniqueId Unique identifier for the notification which is used with clearFormNotification to remove the notification. + * + * @return true if it succeeds, otherwise false. + * + * @remarks Values for level are: ERROR Notification will use the system error icon. + * WARNING Notification will use the system warning icon. + * INFO Notification will use the system info icon. + */ + setFormNotification( message: string, level: Page.ui.FormNotificationLevel | string, uniqueId: string ): boolean; + /** * Clears the form notification described by uniqueId. * * @param {string} uniqueId Unique identifier. * - * @return true if it succeeds, otherwise false. + * @return True if it succeeds, otherwise false. */ clearFormNotification( uniqueId: string ): boolean; @@ -441,14 +668,15 @@ declare namespace Xrm getViewPortWidth(): number; /** - * Re-evaluates the ribbon's configured EnableRules + * Re-evaluates the ribbon's configured EnableRules. * * @remarks This method does not work with Microsoft Dynamics CRM for tablets. */ refreshRibbon(): void; - setFormNotification(message: string, level: Page.ui.FormNotificationLevel | string, uniqueId: string ): boolean; - + /** + * The business process flow API, used to interact with the business process flow control in a form. + */ process: Page.ui.ProcessManager; /** @@ -474,6 +702,11 @@ declare namespace Xrm * A reference to the collection of tabs on the form. */ tabs: Collection.ItemCollection; + + /** + * A collection of all the quick view controls on a form using the new form rendering engine (also called "turbo forms"). + */ + quickForms: Collection.ItemCollection; } /** @@ -481,38 +714,115 @@ declare namespace Xrm */ export module Async { - /** - * Object passed to ErrorCallbackDelegate - */ - export interface ErrorCallbackObject - { - errorCode: number; - message: string; - } - - export interface SuccessCallbackObject - { - savedEntityReference: Page.LookupValue; - } - /** * Called when the operation is successful. - * Currently, only the Xrm.Utility.openQuickCreate successCallback - * is passed a parameter so an optional parameter for it is included */ - export type SuccessCallbackDelegate = (object?: SuccessCallbackObject ) => void; - + export type SuccessCallbackDelegate = () => void; + /** * Called when the operation fails. * - * @param {ErrorCallbackObject} error The error object + * @param {ErrorCallbackObject} error The error object. */ export type ErrorCallbackDelegate = ( error: ErrorCallbackObject ) => void; /** - * Interface for Xrm.Page.data promises. + * Called when the Xrm.Utility.openQuickCreate operation is successful and a new record has been created. + * + * @param {OpenQuickCreateSuccessCallbackObject} record An object which contains a lookup value which identifies the record which has been created. + * + * @see {Xrm.Utility.openQuickCreate} */ - export interface XrmPromise + export type QuickCreateSuccessCallbackDelegate = ( record: OpenQuickCreateSuccessCallbackObject ) => void; + + /** + * Called when the offline operation is successful. + * + * @param {OfflineOperationSuccessCallbackObject} record The record returned from the operation. + * + * @see {Xrm.Mobile.offline} + */ + export type OfflineOperationSuccessCallbackDelegate = ( record: OfflineOperationSuccessCallbackObject ) => void; + + /** + * Called when the offline retrieve multiple operation is successful. + * + * @param {OfflineRetrieveMultipleSuccessCallbackDelegate} resultSet The dictionary of records retrieved from the operation. + * + * @see {Xrm.Mobile.offline.retrieveMultipleRecords} + */ + export type OfflineRetrieveMultipleSuccessCallbackDelegate = (resultSet: { [key: string]: any }[]) => void; + + /** + * Called when the operation fails. + * + * @param {OfflineErrorCallbackObject} error The error object. + * + * @see {Xrm.Mobile.offline} + */ + export type OfflineErrorCallbackDelegate = (error: OfflineErrorCallbackObject) => void; + + + /** + * Object passed to ErrorCallbackDelegate. + */ + export interface ErrorCallbackObject + { + /** + * The error code. + */ + errorCode: number; + + /** + * An error message describing the issue. + */ + message: string; + } + + /** + * Object passed to QuickCreateSuccessCallbackDelegate. + */ + export interface OpenQuickCreateSuccessCallbackObject + { + /** + * A lookup value which identifies the record which has been created. + */ + savedEntityReference: Page.LookupValue; + } + + /** + * Object passed to OfflineOperationSuccessCallbackDelegate; + */ + export interface OfflineOperationSuccessCallbackObject + { + /** + * GUID of the record; + */ + id: string; + /** + * Logical name of the entity. + */ + logicalName: string; + } + + /** + * Object passed to OfflineErrorCallbackDelegate. + */ + export interface OfflineErrorCallbackObject extends ErrorCallbackObject + { + /** + * An internal error message that might contain additional details about the issue. + */ + debugMessage: string; + } + + /** + * Interface for asynchronous promises used in Xrm.Page.data and Xrm.Utility.openQuickCreate. + * + * @tparam TSuccessCallback Generic success callback parameter. + * @tparam TErrorCallback Generic error callback parameter. + */ + export interface XrmPromise { /** * A basic 'then' promise. @@ -520,7 +830,7 @@ declare namespace Xrm * @param {SuccessCallbackDelegate} successCallback The success callback. * @param {ErrorCallbackDelegate} errorCallback The error callback. */ - then( successCallback: SuccessCallbackDelegate, errorCallback: ErrorCallbackDelegate ): void; + then( successCallback: TSuccessCallback, errorCallback: TErrorCallback ): void; } } @@ -633,19 +943,57 @@ declare namespace Xrm * Requirement Level for Xrm.Page.Attribute.getRequiredLevel() and Xrm.Page.Attribute.setRequiredLevel(). */ export type RequirementLevel = "none" | "recommended" | "required"; + /** * Save Modes for Xrm.Page.Entity.save(). */ export type SaveMode = "saveandclose" | "saveandnew"; + /** * Status for Xrm.Page.Stage.getStatus(). */ export type Status = "active" | "inactive"; + /** * Submit Mode for Xrm.Page.Attribute.getSubmitMode() and Xrm.Page.Attribute.setSubmitMode(). */ export type SubmitMode = "always" | "dirty" | "never"; + + /** + * Control types for Xrm.Page.Control.getControlType(). + */ + export type ControlType = "standard" | "iframe" | "lookup" | "optionset" | "subgrid" | "webresource" | "notes" | "timercontrol" | "kbsearch" | "quickform"; + /** + * Date attribute formats for Xrm.Page.Attribute.getFormat(), used by DateAttribute. + */ + export type DateAttributeFormat = "date" | "datetime"; + + /** + * Integer attribute formats for Xrm.Page.Attribute.getFormat(), used by NumberAttribute. + */ + export type IntegerAttributeFormat = "duration" | "none"; + + /** + * OptionSet attribute formats for Xrm.Page.Attribute.getFormat(), used by OptionSetAttribute. + */ + export type OptionSetAttributeFormat = "language" | "timezone"; + + /** + * String attribute formats for Xrm.Page.Attribute.getFormat(), used by StringAttribute. + */ + export type StringAttributeFormat = "email" | "phone" | "text" | "textarea" | "tickersymbol" | "url"; + + /** + * Attribute types for Xrm.ui.ProcessMonitor Xrm.Page.Attribute.setDisplayState(). + */ + export type AttributeType = "boolean" | "datetime" | "decimal" | "double" | "integer" | "lookup" | "memo" | "money" | "optionset" | "string"; + + /** + * Attribute formats for Xrm.Page.Attribute.getFormat(). + */ + export type AttributeFormat = DateAttributeFormat | IntegerAttributeFormat | OptionSetAttributeFormat | StringAttributeFormat; + /** * Interface for a CRM Business Process Flow instance. */ @@ -836,9 +1184,9 @@ declare namespace Xrm } /** - * Base interface for UI elements. + * Interface for UI elements with labels. */ - export interface UiElement + export interface UiLabelElement { /** * Gets the label. @@ -846,21 +1194,33 @@ declare namespace Xrm * @return The label. */ getLabel(): string; - - /** - * Gets the visibility state. - * - * @return true if the tab is visible, otherwise false. - */ - getVisible(): boolean; - + /** * Sets the label. * * @param {string} label The label. */ setLabel( label: string ): void; + } + /** + * Interface for UI elements which can have the visibility value read. + */ + export interface UiCanGetVisibleElement + { + /** + * Gets the visibility state. + * + * @return true if the tab is visible, otherwise false. + */ + getVisible(): boolean; + } + + /** + * Base interface for standard UI elements. + */ + export interface UiStandardElement extends UiCanGetVisibleElement, UiLabelElement + { /** * Sets the visibility state. * @@ -879,15 +1239,44 @@ declare namespace Xrm */ setFocus(): void; } + + /** + * Interface for controls which methods provide immediate feedback or take actions as user types in a control. + * Contains methods which can be used to perform data validations in a control even before the user commits (saves) the value in a form. + */ + export interface UiKeyPressable + { + /** + * Use this to add a function as an event handler for the keypress event so that the function is called when you type a character in the specific text or number field. + * For a sample JavaScript code that uses the addOnKeyPress method to configure the auto-completion experience, see Sample: Auto-complete in CRM controls. + * + * @param {ContextSensitiveHandler} handler The function reference. + */ + addOnKeyPress( handler: ContextSensitiveHandler ): void; + + /** + * Use this to manually fire an event handler that you created for a specific text or number field to be executed on the keypress event. + */ + fireOnKeyPress(): void; + + /** + * Use this to remove an event handler for a text or number field that you added using addOnKeyPress. + * + * Remarks: If an anonymous function is set using addOnKeyPress, it can’t be removed using this method. + * @param {ContextSensitiveHandler} handler The function reference. + */ + removeOnKeyPress( handler: ContextSensitiveHandler ): void; + } /** * Interface for Result value of AutoCompleteResultSet */ - export interface AutoCompleteResult { + export interface AutoCompleteResult + { /** * The Identifier */ - id: string|number; + id: string | number; /** * Url of the icon to display @@ -903,7 +1292,8 @@ declare namespace Xrm /** * Interface for command of AutoCompleteResultSet. This is displayed at the bottom of the auto complete view */ - export interface AutoCompleteCommand { + export interface AutoCompleteCommand + { /** * The Identifier */ @@ -928,7 +1318,8 @@ declare namespace Xrm /** * Interface for showAutoComplete argument */ - export interface AutoCompleteResultSet { + export interface AutoCompleteResultSet + { /** * Results to show */ @@ -983,17 +1374,17 @@ declare namespace Xrm export interface Privilege { /** - * true if the user can read. + * True if the user can read. */ canRead: boolean; /** - * true if the user can update. + * True if the user can update. */ canUpdate: boolean; /** - * true if the user can create. + * True if the user can create. */ canCreate: boolean; } @@ -1032,7 +1423,7 @@ declare namespace Xrm * string */ getAttributeType(): string; - + /** * Gets the attribute format. * @@ -1053,7 +1444,7 @@ declare namespace Xrm * timezone (optionset) * url (string) */ - getFormat(): string; + getFormat(): AttributeFormat; /** * Gets a boolean value indicating whether this Attribute has unsaved changes. @@ -1111,7 +1502,7 @@ declare namespace Xrm * * @param {string} requirementLevel The requirement level, as either "none", "required", or "recommended" */ - setRequiredLevel(requirementLevel: RequirementLevel | string): void; + setRequiredLevel( requirementLevel: RequirementLevel | string ): void; /** * Sets the submit mode. @@ -1120,12 +1511,26 @@ declare namespace Xrm * * @remarks The default value is "dirty" */ - setSubmitMode(submitMode: SubmitMode | string): void; + setSubmitMode( submitMode: SubmitMode | string ): void; /** * A collection of all the controls on the form that interface with this attribute. */ controls: Collection.ItemCollection; + + /** + * Gets the value. + * + * @return The value. + */ + getValue(): any; + + /** + * Sets the value. + * + * @param {any} value The value. + */ + setValue( value: any ): void; } /** @@ -1135,6 +1540,16 @@ declare namespace Xrm */ export interface NumberAttribute extends Attribute { + /** + * Gets the attribute format. + * + * @return The format of the attribute. + * + * @remarks Values returned are: duration + * none + */ + getFormat(): IntegerAttributeFormat; + /** * Gets the maximum value allowed. * @@ -1171,6 +1586,11 @@ declare namespace Xrm * @remarks Attributes on Quick Create Forms will not save values set with this method. */ setValue( value: number ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; } /** @@ -1180,6 +1600,20 @@ declare namespace Xrm */ export interface StringAttribute extends Attribute { + /** + * Gets the attribute format. + * + * @return The format of the attribute. + * + * @remarks Values returned are: email + * phone + * text + * textarea + * tickersymbol + * url + */ + getFormat(): StringAttributeFormat; + /** * Gets maximum length allowed. * @@ -1206,6 +1640,11 @@ declare namespace Xrm * with this method. */ setValue( value: string ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; } /** @@ -1219,7 +1658,8 @@ declare namespace Xrm * Gets the initial value of the attribute. * * @return The initial value. - * @remarks Valid for optionset and boolean attribute types + * + * @remarks Valid for OptionSet and boolean attribute types */ getInitialValue(): number | boolean; } @@ -1255,6 +1695,16 @@ declare namespace Xrm */ export interface DateAttribute extends Attribute { + /** + * Gets the attribute format. + * + * @return The format of the attribute. + * + * @remarks Values returned are: date + * datetime + */ + getFormat(): DateAttributeFormat; + /** * Gets the value. * @@ -1270,6 +1720,11 @@ declare namespace Xrm * @remarks Attributes on Quick Create Forms will not save values set with this method. */ setValue( value: Date ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; } /** @@ -1279,6 +1734,16 @@ declare namespace Xrm */ export interface OptionSetAttribute extends EnumAttribute { + /** + * Gets the attribute format. + * + * @return The format of the attribute. + * + * @remarks Values returned are: language + * timezone + */ + getFormat(): OptionSetAttributeFormat; + /** * Gets the option matching a value. * @@ -1336,6 +1801,11 @@ declare namespace Xrm * with this method. */ setValue( value: number ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; } /** @@ -1367,6 +1837,11 @@ declare namespace Xrm * @remarks Attributes on Quick Create Forms will not save values set with this method. */ setValue( value: LookupValue[] ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; } /** @@ -1464,6 +1939,7 @@ declare namespace Xrm * Gets save mode, as an integer. * * @return The save mode. + * * @remarks Values returned are: 1 Save * 2 Save and Close * 59 Save and New @@ -1488,6 +1964,7 @@ declare namespace Xrm /** * Prevents the save operation from being submitted to the server. + * * @remarks All remaining "on save" handlers will continue execution. */ preventDefault(): void; @@ -1631,6 +2108,7 @@ declare namespace Xrm * Called when process change methods have completed. * * @param {string} status The result of the process change operation. + * * @remarks Values returned are: success (The operation succeeded.) * crossEntity (The previous stage is for a different entity.) * beginning (The active stage is the first stage of the active path.) @@ -1645,29 +2123,19 @@ declare namespace Xrm */ export type ProcessDictionary = { [index: string]: string }; } - + /** * Interface for Xrm.Page.ui controls. * * @sa UiElement */ - export interface Control extends UiElement, UiFocusable + export interface Control extends UiLabelElement, UiCanGetVisibleElement { /** - * Clears the notification identified by uniqueId. - * - * @param {string} uniqueId (Optional) Unique identifier. - * - * @return true if it succeeds, false if it fails. - * - * @remarks If the uniqueId parameter is not used, the current notification shown will be removed. - */ - clearNotification( uniqueId?: string ): boolean; - - /** - * Gets the control's type. + * Gets the controls type. * * @return The control type. + * * @remarks Values returned are: standard * iframe * lookup @@ -1677,16 +2145,12 @@ declare namespace Xrm * notes * timercontrol * kbsearch (CRM Online Only, use parature.d.ts) + * quickform (see ui.QuickForm) + * customcontrol: . (A custom control for mobile phone and tablet clients). + * customsubgrid: . (A custom dataset control for mobile phone and tablet clients). */ - getControlType(): string; - - /** - * Gets a boolean value, indicating whether the control is disabled. - * - * @return true if it is disabled, otherwise false. - */ - getDisabled(): boolean; - + getControlType(): ControlType | string; + /** * Gets the name of the control on the form. * @@ -1711,7 +2175,33 @@ declare namespace Xrm * @return The parent Section. */ getParent(): Section; - + } + + /** + * Interface for a standard control. + * + * @sa Control + */ + export interface StandardControl extends Control, UiStandardElement, UiFocusable + { + /** + * Clears the notification identified by uniqueId. + * + * @param {string} uniqueId (Optional) Unique identifier. + * + * @return true if it succeeds, false if it fails. + * + * @remarks If the uniqueId parameter is not used, the current notification shown will be removed. + */ + clearNotification( uniqueId?: string ): boolean; + + /** + * Gets a boolean value, indicating whether the control is disabled. + * + * @return true if it is disabled, otherwise false. + */ + getDisabled(): boolean; + /** * Sets the state of the control to either enabled, or disabled. * @@ -1731,15 +2221,7 @@ declare namespace Xrm * appears next to the control. Tapping on the icon will display the message. */ setNotification( message: string, uniqueId: string ): boolean; - } - /** - * Interface for a standard control. - * - * @sa Control - */ - export interface StandardControl extends Control - { /** * Gets the control's bound attribute. * @@ -1756,28 +2238,17 @@ declare namespace Xrm */ getAttribute(): Attribute; } - + /** - * Interace for Auto Lookup Control - * This is not an Entity Lookup, but a control that supports AutoComplete/KeyPress Events (Text) - * NOTE * This interface is not supported for CRM mobile clients (phones or tablets) and the interactive service hub. It is only available for Updated entities. + * Interface for Auto Lookup Control. + * This is not an Entity Lookup, but a control that supports AutoComplete / KeyPress Events (Text or Number) + * + * @remarks This interface is not supported for CRM mobile clients (phones or tablets) and the interactive service hub. It is only available for Updated entities. * * @sa StandardControl */ - export interface AutoLookupControl extends StandardControl { - /** - * Use this to add a function as an event handler for the keypress event so that the function is called when you type a character in the specific text or number field. - * For a sample JavaScript code that uses the addOnKeyPress method to configure the auto-completion experience, see Sample: Auto-complete in CRM controls. - * - * @param {ContextSensitiveHandler} handler The function reference. - */ - addOnKeyPress(handler: ContextSensitiveHandler): void; - - /** - * Use this to manually fire an event handler that you created for a specific text or number field to be executed on the keypress event. - */ - fireOnKeyPress(): void; - + export interface AutoLookupControl extends StandardControl, UiKeyPressable + { /** * Gets the latest value in a control as the user types characters in a specific text or number field. * This method helps you to build interactive experiences by validating data and alerting users as they type characters in a control. @@ -1790,15 +2261,7 @@ declare namespace Xrm * Hides the auto-completion drop-down list configured for a specific text field */ hideAutoComplete(): void; - - /** - * Use this to remove an event handler for a text or number field that you added using addOnKeyPress. - * - * Remarks: If an anonymous function is set using addOnKeyPress, it can’t be removed using this method. - * @param {ContextSensitiveHandler} handler The function reference. - */ - removeOnKeyPress(handler: ContextSensitiveHandler): void; - + /** * Shows upt to 10 matching strings in a drop-down list as users press keys to type charactrer in a specific text field. * On selecting an item in the drop-down list, the value in the text field changes to the selected item, the drop-down list disappears, and the OnChange event for the text field is invoked @@ -1807,6 +2270,36 @@ declare namespace Xrm showAutoComplete(resultSet: AutoCompleteResultSet): void; } + /** + * Interface for a String control. + * + * @sa StandardControl + */ + export interface StringControl extends AutoLookupControl + { + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): StringAttribute; + } + + /** + * Interface for a Number control. + * + * @sa StandardControl + */ + export interface NumberControl extends AutoLookupControl + { + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): NumberAttribute; + } + /** * Interface for a Date control. * @@ -2110,7 +2603,7 @@ declare namespace Xrm * @sa UiElement * @sa UiFocusable */ - export interface Tab extends UiElement, UiFocusable + export interface Tab extends UiStandardElement, UiFocusable { /** * Gets display state of the tab. @@ -2151,7 +2644,7 @@ declare namespace Xrm * * @sa UiElement */ - export interface Section extends UiElement + export interface Section extends UiStandardElement { /** * Gets the name of the section. @@ -2183,14 +2676,14 @@ declare namespace Xrm */ export type FormNotificationLevel = "ERROR" | "INFO" | "WARNING"; - /** + /** * Display States for Xrm.ui.ProcessMonitor.setDisplayState(). - */ + */ export type DisplayState = "collapsed" | "expanded"; - /** + /** * Interface for Xrm.Page.ui.process API - */ + */ export interface ProcessManager { /** @@ -2198,7 +2691,7 @@ declare namespace Xrm * * @param {string} displayState Display state of the process flow control, as either "expanded" or "collapsed" */ - setDisplayState(displayState: ui.DisplayState ): void; + setDisplayState( displayState: ui.DisplayState ): void; /** * Sets the visibility state. @@ -2330,7 +2823,7 @@ declare namespace Xrm } /** - * Interface for a view selector item. This object contains data that identifies a view. Use this as a parameter to + * Interface for a view selector item. This object contains data that identifies a view. Use this as a parameter to * the ViewSelector.setCurrentView method. */ export interface ViewSelectorItem @@ -2342,6 +2835,93 @@ declare namespace Xrm */ getEntityReference(): LookupValue; } + + /** + * Interface for a quick view control instance on a form. + * + * @see {@link https://msdn.microsoft.com/en-us/library/mt736908.aspx#bkmk_isLoaded} for details. + */ + export interface QuickForm extends Control, UiLabelElement, UiCanGetVisibleElement + { + /** + * Gets the constituent controls in a quick view control. + * + * @return An array of controls. + * + * @remarks Constituent controls in a quick view control are read only. + */ + getControl(): Page.Control[]; + + /** + * Gets the constituent controls in a quick view control. + * + * @tparam T A Control type + * @param {string} controlName Name of the control. + * + * @return The control. + * + * @remarks Constituent controls in a quick view control are read only. + */ + getControl( controlName: string ): T; + + /** + * Gets the constituent controls in a quick view control. + * + * @param {string} controlName Name of the control. + * + * @return The control. + * + * @remarks Constituent controls in a quick view control are read only. + */ + getControl( controlName: string ): Page.Control; + + /** + * Gets a control by index. + * + * @tparam T A Control type + * @param {number} index The control index. + * + * @return The control. + * + * @remarks Constituent controls in a quick view control are read only. + */ + getControl( index: number ): T; + + /** + * Gets a control by index. + * + * @param {number} index The control index. + * + * @return The control. + * + * @remarks Constituent controls in a quick view control are read only. + */ + getControl( index: number ): Page.Control; + + /** + * Gets the controls type. + * + * @return Returns a string value that categorizes quick view controls. + */ + getControlType(): "quickform"; + + /** + * Returns whether the data binding for the constituent controls in a quick view control is complete. + * + * @return True is the data binding for a constituent control is complete, otherwise false. + * because the quick view form that the control is bound to may not have loaded completely. + * As a result, using the getAttribute or any data-related methods on a constituent control might not work. + * The isLoaded method for the quick view control helps determine the data binding status for constituent controls in a quick view control. + * + * @remarks The data binding for the constituent controls in a quick view control may not be complete during the main form OnLoad event + */ + isLoaded(): boolean; + + /** + * Refreshes the data displayed in a quick view control. + */ + refresh(): void; + } } /** @@ -2350,7 +2930,7 @@ declare namespace Xrm * @sa UiElement * @sa UiFocusable */ - export interface NavigationItem extends UiElement, UiFocusable + export interface NavigationItem extends UiStandardElement, UiFocusable { /** * Gets the name of the item. @@ -2427,11 +3007,13 @@ declare namespace Xrm /** * Command Bar Display options for Xrm.Url.FormOpenParameters.cmdbar, Xrm.Url.ViewOpenParameters.cmdbar, and Xrm.Utility.FormOpenParameters.cmdbar. */ + export type CmdBarDisplay = "true" | "false"; /** * Navigation Bar Display options for Xrm.Url.FormOpenParameters.navbar, Xrm.Url.ViewOpenParameters.navbar, and Xrm.Utility.FormOpenParameters.navbar. */ export type NavBarDisplay = "entity" | "off" | "on"; + /** * Report Open Action options for Xrm.Url.ReportOpenParameters.actions. */ diff --git a/xrm/xrm-tests.ts b/xrm/xrm-tests.ts index 1893b9b89a..56d8f32b3c 100644 --- a/xrm/xrm-tests.ts +++ b/xrm/xrm-tests.ts @@ -75,7 +75,8 @@ Xrm.Utility.openQuickCreate("account").then(( object ) => { if (object) alert( ` /// Make all controls visible. -Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); }); +// Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); }); // No longer works +Xrm.Page.ui.controls.forEach((control: Xrm.Page.StandardControl) => { control.setVisible(true); }); // Must cast to StandardControl /// Make all tabs and sections visible. @@ -166,4 +167,28 @@ autoCompleteControl.hideAutoComplete(); +/// Demonstrate v8.2 quick form controls + +const quickForm = Xrm.Page.ui.quickForms.get(0); +quickForm.getControlType(); // == "quickform" +quickForm.getName(); +quickForm.getParent(); +quickForm.getVisible(); // From UiCanSetVisibleElement +quickForm.getLabel(); // From UiLabelElement +quickForm.setLabel("Label"); // From UiLabelElement +quickForm.refresh(); + +// Get standard control +const ctrl = Xrm.Page.getControl("controlName"); +ctrl.getControlType() +ctrl.getName(); +ctrl.getParent(); +ctrl.getLabel(); +ctrl.setLabel("Label name"); +ctrl.getVisible(); +ctrl.setVisible(true); + + + + From fe372f86ad9a65e3db8b0bfb8a6527ed5f7c3a6f Mon Sep 17 00:00:00 2001 From: clownwilleatme Date: Tue, 7 Feb 2017 10:20:34 +1100 Subject: [PATCH 2/9] Revert "Adding XRM v8.2 features" This reverts commit 65d062de61c4d7e014d73420c28e0999ab8f6c9d. --- xrm/index.d.ts | 828 +++++++---------------------------------------- xrm/xrm-tests.ts | 27 +- 2 files changed, 124 insertions(+), 731 deletions(-) diff --git a/xrm/index.d.ts b/xrm/index.d.ts index 2ed4cef363..36bd556c13 100644 --- a/xrm/index.d.ts +++ b/xrm/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for Microsoft Dynamics xRM API v8.2 +// Type definitions for Microsoft Dynamics xRM API v8.0 // 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 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare var Xrm: Xrm.XrmStatic; @@ -93,7 +93,7 @@ declare namespace Xrm * Gets a control matching controlName. * * @tparam T A Control type - * @param {string} controlName Name of the control. + * @param {string} controlName Name of the control. * * @return The control. */ @@ -102,22 +102,12 @@ declare namespace Xrm /** * Gets a control matching controlName. * - * @param {string} controlName Name of the control. + * @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. * @@ -176,10 +166,11 @@ declare namespace Xrm * @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; + openQuickCreate( + entityLogicalName: string, + createFromEntity?: Page.LookupValue, + parameters?: Utility.OpenParameters ): Async.XrmPromise; /** * Opens an entity form. @@ -214,194 +205,16 @@ declare namespace Xrm */ openWebResource( webResourceName: string, webResourceData?: string, width?: number, height?: number ): Window; } - - /** - * Provides methods to create and manage records in the mobile clients (for phones tablets). - */ - Mobile: { - /** - * Provides methods to create and manage records in the mobile clients while working in the offline mode. - * - * @see {@link https://msdn.microsoft.com/en-us/library/mt787123.aspx} for details. - */ - offline: { - /** - * Returns whether an entity is offline enabled. - * - * @param {string} entityType The logical name of the entity. - * - * @return {boolean} True if the entity is offline enabled; otherwise False. - */ - isOfflineEnabled( entityType: string ): boolean; - - /** - * Creates an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {Object} data A dictionary object containing key : value pairs for the record to create. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks You cannot create intersect and activity party entities. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ - createRecord( entityType: string, data: { [attributeName: string]: any } ): Async.XrmPromise; - - /** - * Retrieves an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} id GUID of the record to retrieve. - * @param {string} options (Optional) OData system query options to retrieve your data. Supports $select and $expand - * Example: ?$select=name&$expand=primarycontactid($select=contactid,fullname) - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks Only $select option can be specified within $expand. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ - retrieveRecord( entityType: string, id: string, options: string ): Async.XrmPromise; - - /** - * Retrieves a collection of entity records in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} options (Optional) The logical name of the enti - * @param {string} maxPageSize (Optional) A positive number to indicates the number of entity records to be returned per page. - * If you do not specify this parameter, the default value is passed as 5000. - * If the number of records being retrieved is more than maxPageSize, an @odata.nextLink property - * will be returned, and you can use the value of the @odata.nextLink property with a new GET - * request to return next set of records. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks A maximum of 5000 related records can be retrieved when using $expand. - * Only $select option can be specified within $expand. - * $skip query option is not supported. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ - retrieveMultipleRecords( entityType: string, options: string, maxPageSize: number ): Async.XrmPromise; - - /** - * Updates an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} id GUID of the record to update. - * @param {Object} data A dictionary object containing key : value pairs for the record to update. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks You cannot update intersect and activity party entities. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ - updateRecord( entityType: string, id: string, data: { [attributeName: string]: any } ): Async.XrmPromise; - - /** - * Deletes an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} id GUID of the record to delete. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks You cannot delete intersect and activity party entities. - */ - deleteRecord( entityType: string, id: string ): Async.XrmPromise; - } - } - - /** - * Provides methods to display a web page in the side pane of web client. - * - * @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; - } } /** * Client Types for Xrm.Page.context.getClient(). */ export type Client = "Web" | "Outlook" | "Mobile"; - /** * Client States for Xrm.Page.context.getClientState(). */ export type ClientState = "Online" | "Offline"; - /** * Themes for Xrm.Page.context.getCurrentTheme(). */ @@ -441,7 +254,6 @@ declare namespace Xrm * Gets client's base URL for Dynamics CRM * * @return The client's base URL - * * @remarks For Dynamics CRM On-Premises: http(s)://server/org * For Dynamics CRM Online: https://org.crm.dynamics.com * For Dynamics CRM for Outlook (Offline): http://localhost:2525 @@ -542,20 +354,6 @@ declare namespace Xrm prependOrgName( sPath: string ): string; } - /** - * Defines save options to control how appointment, recurring appointment, or service activity records are processed. - * - * @see {@link https://msdn.microsoft.com/en-us/library/dn481607.aspx#Anchor_2} for details. - */ - interface SaveOptions - { - /** - * Indicates whether to use the Book or Reschedule messages rather than the Create or Update messages. - * Applicable to appointment, recurring appointment, or service activity records. - */ - UseSchedulingEngine?: boolean; - } - /** * Interface for the Xrm.Page.data object. */ @@ -566,25 +364,16 @@ declare namespace Xrm * * @param {boolean} save true to save the record, after the refresh. * - * @return {Async.XrmPromise} Returns an asynchronous promise. + * @return An Async.XrmPromise. */ - refresh( save: boolean ): Async.XrmPromise; + refresh( save: boolean ): Async.XrmPromise; /** * Asynchronously saves the record. * - * @return {Async.XrmPromise} Returns an asynchronous promise. + * @return An Async.XrmPromise. */ - save(): Async.XrmPromise; - - /** - * Asynchronously saves the record with the option to set callback functions to be executed after the save operation is completed. - * - * @param {saveOptions} saveOptions Options to control how appointment, recurring appointment, or service activity records are processed. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - */ - save( saveOptions: SaveOptions ): Async.XrmPromise; + save(): Async.XrmPromise; /** * The record context of the form. @@ -604,28 +393,12 @@ declare namespace Xrm */ export interface Ui { - /** - * Displays a form level notification. Any number of notifications can be displayed and will remain until removed using clearFormNotification. - * The height of the notification area is limited so each new message will be added to the top. - * - * @param {string} message The text of the notification message. - * @param {Page.ui.FormNotificationLevel} level The level of the notification which defines how the message will be displayed, such as the icon. - * @param {string} uniqueId Unique identifier for the notification which is used with clearFormNotification to remove the notification. - * - * @return true if it succeeds, otherwise false. - * - * @remarks Values for level are: ERROR Notification will use the system error icon. - * WARNING Notification will use the system warning icon. - * INFO Notification will use the system info icon. - */ - setFormNotification( message: string, level: Page.ui.FormNotificationLevel | string, uniqueId: string ): boolean; - /** * Clears the form notification described by uniqueId. * * @param {string} uniqueId Unique identifier. * - * @return True if it succeeds, otherwise false. + * @return true if it succeeds, otherwise false. */ clearFormNotification( uniqueId: string ): boolean; @@ -668,15 +441,14 @@ declare namespace Xrm getViewPortWidth(): number; /** - * Re-evaluates the ribbon's configured EnableRules. + * Re-evaluates the ribbon's configured EnableRules * * @remarks This method does not work with Microsoft Dynamics CRM for tablets. */ refreshRibbon(): void; - /** - * The business process flow API, used to interact with the business process flow control in a form. - */ + setFormNotification(message: string, level: Page.ui.FormNotificationLevel | string, uniqueId: string ): boolean; + process: Page.ui.ProcessManager; /** @@ -702,11 +474,6 @@ declare namespace Xrm * A reference to the collection of tabs on the form. */ tabs: Collection.ItemCollection; - - /** - * A collection of all the quick view controls on a form using the new form rendering engine (also called "turbo forms"). - */ - quickForms: Collection.ItemCollection; } /** @@ -715,114 +482,37 @@ declare namespace Xrm export module Async { /** - * Called when the operation is successful. - */ - export type SuccessCallbackDelegate = () => void; - - /** - * Called when the operation fails. - * - * @param {ErrorCallbackObject} error The error object. - */ - export type ErrorCallbackDelegate = ( error: ErrorCallbackObject ) => void; - - /** - * Called when the Xrm.Utility.openQuickCreate operation is successful and a new record has been created. - * - * @param {OpenQuickCreateSuccessCallbackObject} record An object which contains a lookup value which identifies the record which has been created. - * - * @see {Xrm.Utility.openQuickCreate} - */ - export type QuickCreateSuccessCallbackDelegate = ( record: OpenQuickCreateSuccessCallbackObject ) => void; - - /** - * Called when the offline operation is successful. - * - * @param {OfflineOperationSuccessCallbackObject} record The record returned from the operation. - * - * @see {Xrm.Mobile.offline} - */ - export type OfflineOperationSuccessCallbackDelegate = ( record: OfflineOperationSuccessCallbackObject ) => void; - - /** - * Called when the offline retrieve multiple operation is successful. - * - * @param {OfflineRetrieveMultipleSuccessCallbackDelegate} resultSet The dictionary of records retrieved from the operation. - * - * @see {Xrm.Mobile.offline.retrieveMultipleRecords} - */ - export type OfflineRetrieveMultipleSuccessCallbackDelegate = (resultSet: { [key: string]: any }[]) => void; - - /** - * Called when the operation fails. - * - * @param {OfflineErrorCallbackObject} error The error object. - * - * @see {Xrm.Mobile.offline} - */ - export type OfflineErrorCallbackDelegate = (error: OfflineErrorCallbackObject) => void; - - - /** - * Object passed to ErrorCallbackDelegate. + * Object passed to ErrorCallbackDelegate */ export interface ErrorCallbackObject { - /** - * The error code. - */ errorCode: number; - - /** - * An error message describing the issue. - */ message: string; } - - /** - * Object passed to QuickCreateSuccessCallbackDelegate. - */ - export interface OpenQuickCreateSuccessCallbackObject - { - /** - * A lookup value which identifies the record which has been created. - */ + + export interface SuccessCallbackObject + { savedEntityReference: Page.LookupValue; } /** - * Object passed to OfflineOperationSuccessCallbackDelegate; + * Called when the operation is successful. + * Currently, only the Xrm.Utility.openQuickCreate successCallback + * is passed a parameter so an optional parameter for it is included */ - export interface OfflineOperationSuccessCallbackObject - { - /** - * GUID of the record; - */ - id: string; - /** - * Logical name of the entity. - */ - logicalName: string; - } - - /** - * Object passed to OfflineErrorCallbackDelegate. - */ - export interface OfflineErrorCallbackObject extends ErrorCallbackObject - { - /** - * An internal error message that might contain additional details about the issue. - */ - debugMessage: string; - } + export type SuccessCallbackDelegate = (object?: SuccessCallbackObject ) => void; /** - * Interface for asynchronous promises used in Xrm.Page.data and Xrm.Utility.openQuickCreate. + * Called when the operation fails. * - * @tparam TSuccessCallback Generic success callback parameter. - * @tparam TErrorCallback Generic error callback parameter. + * @param {ErrorCallbackObject} error The error object */ - export interface XrmPromise + export type ErrorCallbackDelegate = ( error: ErrorCallbackObject ) => void; + + /** + * Interface for Xrm.Page.data promises. + */ + export interface XrmPromise { /** * A basic 'then' promise. @@ -830,7 +520,7 @@ declare namespace Xrm * @param {SuccessCallbackDelegate} successCallback The success callback. * @param {ErrorCallbackDelegate} errorCallback The error callback. */ - then( successCallback: TSuccessCallback, errorCallback: TErrorCallback ): void; + then( successCallback: SuccessCallbackDelegate, errorCallback: ErrorCallbackDelegate ): void; } } @@ -943,57 +633,19 @@ declare namespace Xrm * Requirement Level for Xrm.Page.Attribute.getRequiredLevel() and Xrm.Page.Attribute.setRequiredLevel(). */ export type RequirementLevel = "none" | "recommended" | "required"; - /** * Save Modes for Xrm.Page.Entity.save(). */ export type SaveMode = "saveandclose" | "saveandnew"; - /** * Status for Xrm.Page.Stage.getStatus(). */ export type Status = "active" | "inactive"; - /** * Submit Mode for Xrm.Page.Attribute.getSubmitMode() and Xrm.Page.Attribute.setSubmitMode(). */ export type SubmitMode = "always" | "dirty" | "never"; - - /** - * Control types for Xrm.Page.Control.getControlType(). - */ - export type ControlType = "standard" | "iframe" | "lookup" | "optionset" | "subgrid" | "webresource" | "notes" | "timercontrol" | "kbsearch" | "quickform"; - /** - * Date attribute formats for Xrm.Page.Attribute.getFormat(), used by DateAttribute. - */ - export type DateAttributeFormat = "date" | "datetime"; - - /** - * Integer attribute formats for Xrm.Page.Attribute.getFormat(), used by NumberAttribute. - */ - export type IntegerAttributeFormat = "duration" | "none"; - - /** - * OptionSet attribute formats for Xrm.Page.Attribute.getFormat(), used by OptionSetAttribute. - */ - export type OptionSetAttributeFormat = "language" | "timezone"; - - /** - * String attribute formats for Xrm.Page.Attribute.getFormat(), used by StringAttribute. - */ - export type StringAttributeFormat = "email" | "phone" | "text" | "textarea" | "tickersymbol" | "url"; - - /** - * Attribute types for Xrm.ui.ProcessMonitor Xrm.Page.Attribute.setDisplayState(). - */ - export type AttributeType = "boolean" | "datetime" | "decimal" | "double" | "integer" | "lookup" | "memo" | "money" | "optionset" | "string"; - - /** - * Attribute formats for Xrm.Page.Attribute.getFormat(). - */ - export type AttributeFormat = DateAttributeFormat | IntegerAttributeFormat | OptionSetAttributeFormat | StringAttributeFormat; - /** * Interface for a CRM Business Process Flow instance. */ @@ -1184,9 +836,9 @@ declare namespace Xrm } /** - * Interface for UI elements with labels. + * Base interface for UI elements. */ - export interface UiLabelElement + export interface UiElement { /** * Gets the label. @@ -1194,33 +846,21 @@ declare namespace Xrm * @return The label. */ getLabel(): string; - - /** - * Sets the label. - * - * @param {string} label The label. - */ - setLabel( label: string ): void; - } - /** - * Interface for UI elements which can have the visibility value read. - */ - export interface UiCanGetVisibleElement - { /** * Gets the visibility state. * * @return true if the tab is visible, otherwise false. */ getVisible(): boolean; - } - - /** - * Base interface for standard UI elements. - */ - export interface UiStandardElement extends UiCanGetVisibleElement, UiLabelElement - { + + /** + * Sets the label. + * + * @param {string} label The label. + */ + setLabel( label: string ): void; + /** * Sets the visibility state. * @@ -1239,44 +879,15 @@ declare namespace Xrm */ setFocus(): void; } - - /** - * Interface for controls which methods provide immediate feedback or take actions as user types in a control. - * Contains methods which can be used to perform data validations in a control even before the user commits (saves) the value in a form. - */ - export interface UiKeyPressable - { - /** - * Use this to add a function as an event handler for the keypress event so that the function is called when you type a character in the specific text or number field. - * For a sample JavaScript code that uses the addOnKeyPress method to configure the auto-completion experience, see Sample: Auto-complete in CRM controls. - * - * @param {ContextSensitiveHandler} handler The function reference. - */ - addOnKeyPress( handler: ContextSensitiveHandler ): void; - - /** - * Use this to manually fire an event handler that you created for a specific text or number field to be executed on the keypress event. - */ - fireOnKeyPress(): void; - - /** - * Use this to remove an event handler for a text or number field that you added using addOnKeyPress. - * - * Remarks: If an anonymous function is set using addOnKeyPress, it can’t be removed using this method. - * @param {ContextSensitiveHandler} handler The function reference. - */ - removeOnKeyPress( handler: ContextSensitiveHandler ): void; - } /** * Interface for Result value of AutoCompleteResultSet */ - export interface AutoCompleteResult - { + export interface AutoCompleteResult { /** * The Identifier */ - id: string | number; + id: string|number; /** * Url of the icon to display @@ -1292,8 +903,7 @@ declare namespace Xrm /** * Interface for command of AutoCompleteResultSet. This is displayed at the bottom of the auto complete view */ - export interface AutoCompleteCommand - { + export interface AutoCompleteCommand { /** * The Identifier */ @@ -1318,8 +928,7 @@ declare namespace Xrm /** * Interface for showAutoComplete argument */ - export interface AutoCompleteResultSet - { + export interface AutoCompleteResultSet { /** * Results to show */ @@ -1374,17 +983,17 @@ declare namespace Xrm export interface Privilege { /** - * True if the user can read. + * true if the user can read. */ canRead: boolean; /** - * True if the user can update. + * true if the user can update. */ canUpdate: boolean; /** - * True if the user can create. + * true if the user can create. */ canCreate: boolean; } @@ -1423,7 +1032,7 @@ declare namespace Xrm * string */ getAttributeType(): string; - + /** * Gets the attribute format. * @@ -1444,7 +1053,7 @@ declare namespace Xrm * timezone (optionset) * url (string) */ - getFormat(): AttributeFormat; + getFormat(): string; /** * Gets a boolean value indicating whether this Attribute has unsaved changes. @@ -1502,7 +1111,7 @@ declare namespace Xrm * * @param {string} requirementLevel The requirement level, as either "none", "required", or "recommended" */ - setRequiredLevel( requirementLevel: RequirementLevel | string ): void; + setRequiredLevel(requirementLevel: RequirementLevel | string): void; /** * Sets the submit mode. @@ -1511,26 +1120,12 @@ declare namespace Xrm * * @remarks The default value is "dirty" */ - setSubmitMode( submitMode: SubmitMode | string ): void; + setSubmitMode(submitMode: SubmitMode | string): void; /** * A collection of all the controls on the form that interface with this attribute. */ controls: Collection.ItemCollection; - - /** - * Gets the value. - * - * @return The value. - */ - getValue(): any; - - /** - * Sets the value. - * - * @param {any} value The value. - */ - setValue( value: any ): void; } /** @@ -1540,16 +1135,6 @@ declare namespace Xrm */ export interface NumberAttribute extends Attribute { - /** - * Gets the attribute format. - * - * @return The format of the attribute. - * - * @remarks Values returned are: duration - * none - */ - getFormat(): IntegerAttributeFormat; - /** * Gets the maximum value allowed. * @@ -1586,11 +1171,6 @@ declare namespace Xrm * @remarks Attributes on Quick Create Forms will not save values set with this method. */ setValue( value: number ): void; - - /** - * A collection of all the controls on the form that interface with this attribute. - */ - controls: Collection.ItemCollection; } /** @@ -1600,20 +1180,6 @@ declare namespace Xrm */ export interface StringAttribute extends Attribute { - /** - * Gets the attribute format. - * - * @return The format of the attribute. - * - * @remarks Values returned are: email - * phone - * text - * textarea - * tickersymbol - * url - */ - getFormat(): StringAttributeFormat; - /** * Gets maximum length allowed. * @@ -1640,11 +1206,6 @@ declare namespace Xrm * with this method. */ setValue( value: string ): void; - - /** - * A collection of all the controls on the form that interface with this attribute. - */ - controls: Collection.ItemCollection; } /** @@ -1658,8 +1219,7 @@ declare namespace Xrm * Gets the initial value of the attribute. * * @return The initial value. - * - * @remarks Valid for OptionSet and boolean attribute types + * @remarks Valid for optionset and boolean attribute types */ getInitialValue(): number | boolean; } @@ -1695,16 +1255,6 @@ declare namespace Xrm */ export interface DateAttribute extends Attribute { - /** - * Gets the attribute format. - * - * @return The format of the attribute. - * - * @remarks Values returned are: date - * datetime - */ - getFormat(): DateAttributeFormat; - /** * Gets the value. * @@ -1720,11 +1270,6 @@ declare namespace Xrm * @remarks Attributes on Quick Create Forms will not save values set with this method. */ setValue( value: Date ): void; - - /** - * A collection of all the controls on the form that interface with this attribute. - */ - controls: Collection.ItemCollection; } /** @@ -1734,16 +1279,6 @@ declare namespace Xrm */ export interface OptionSetAttribute extends EnumAttribute { - /** - * Gets the attribute format. - * - * @return The format of the attribute. - * - * @remarks Values returned are: language - * timezone - */ - getFormat(): OptionSetAttributeFormat; - /** * Gets the option matching a value. * @@ -1801,11 +1336,6 @@ declare namespace Xrm * with this method. */ setValue( value: number ): void; - - /** - * A collection of all the controls on the form that interface with this attribute. - */ - controls: Collection.ItemCollection; } /** @@ -1837,11 +1367,6 @@ declare namespace Xrm * @remarks Attributes on Quick Create Forms will not save values set with this method. */ setValue( value: LookupValue[] ): void; - - /** - * A collection of all the controls on the form that interface with this attribute. - */ - controls: Collection.ItemCollection; } /** @@ -1939,7 +1464,6 @@ declare namespace Xrm * Gets save mode, as an integer. * * @return The save mode. - * * @remarks Values returned are: 1 Save * 2 Save and Close * 59 Save and New @@ -1964,7 +1488,6 @@ declare namespace Xrm /** * Prevents the save operation from being submitted to the server. - * * @remarks All remaining "on save" handlers will continue execution. */ preventDefault(): void; @@ -2108,7 +1631,6 @@ declare namespace Xrm * Called when process change methods have completed. * * @param {string} status The result of the process change operation. - * * @remarks Values returned are: success (The operation succeeded.) * crossEntity (The previous stage is for a different entity.) * beginning (The active stage is the first stage of the active path.) @@ -2123,19 +1645,29 @@ declare namespace Xrm */ export type ProcessDictionary = { [index: string]: string }; } - + /** * Interface for Xrm.Page.ui controls. * * @sa UiElement */ - export interface Control extends UiLabelElement, UiCanGetVisibleElement + export interface Control extends UiElement, UiFocusable { /** - * Gets the controls type. + * Clears the notification identified by uniqueId. + * + * @param {string} uniqueId (Optional) Unique identifier. + * + * @return true if it succeeds, false if it fails. + * + * @remarks If the uniqueId parameter is not used, the current notification shown will be removed. + */ + clearNotification( uniqueId?: string ): boolean; + + /** + * Gets the control's type. * * @return The control type. - * * @remarks Values returned are: standard * iframe * lookup @@ -2145,12 +1677,16 @@ declare namespace Xrm * notes * timercontrol * kbsearch (CRM Online Only, use parature.d.ts) - * quickform (see ui.QuickForm) - * customcontrol: . (A custom control for mobile phone and tablet clients). - * customsubgrid: . (A custom dataset control for mobile phone and tablet clients). */ - getControlType(): ControlType | string; - + getControlType(): string; + + /** + * Gets a boolean value, indicating whether the control is disabled. + * + * @return true if it is disabled, otherwise false. + */ + getDisabled(): boolean; + /** * Gets the name of the control on the form. * @@ -2175,33 +1711,7 @@ declare namespace Xrm * @return The parent Section. */ getParent(): Section; - } - - /** - * Interface for a standard control. - * - * @sa Control - */ - export interface StandardControl extends Control, UiStandardElement, UiFocusable - { - /** - * Clears the notification identified by uniqueId. - * - * @param {string} uniqueId (Optional) Unique identifier. - * - * @return true if it succeeds, false if it fails. - * - * @remarks If the uniqueId parameter is not used, the current notification shown will be removed. - */ - clearNotification( uniqueId?: string ): boolean; - - /** - * Gets a boolean value, indicating whether the control is disabled. - * - * @return true if it is disabled, otherwise false. - */ - getDisabled(): boolean; - + /** * Sets the state of the control to either enabled, or disabled. * @@ -2221,7 +1731,15 @@ declare namespace Xrm * appears next to the control. Tapping on the icon will display the message. */ setNotification( message: string, uniqueId: string ): boolean; + } + /** + * Interface for a standard control. + * + * @sa Control + */ + export interface StandardControl extends Control + { /** * Gets the control's bound attribute. * @@ -2238,17 +1756,28 @@ declare namespace Xrm */ getAttribute(): Attribute; } - + /** - * Interface for Auto Lookup Control. - * This is not an Entity Lookup, but a control that supports AutoComplete / KeyPress Events (Text or Number) - * - * @remarks This interface is not supported for CRM mobile clients (phones or tablets) and the interactive service hub. It is only available for Updated entities. + * Interace for Auto Lookup Control + * This is not an Entity Lookup, but a control that supports AutoComplete/KeyPress Events (Text) + * NOTE * This interface is not supported for CRM mobile clients (phones or tablets) and the interactive service hub. It is only available for Updated entities. * * @sa StandardControl */ - export interface AutoLookupControl extends StandardControl, UiKeyPressable - { + export interface AutoLookupControl extends StandardControl { + /** + * Use this to add a function as an event handler for the keypress event so that the function is called when you type a character in the specific text or number field. + * For a sample JavaScript code that uses the addOnKeyPress method to configure the auto-completion experience, see Sample: Auto-complete in CRM controls. + * + * @param {ContextSensitiveHandler} handler The function reference. + */ + addOnKeyPress(handler: ContextSensitiveHandler): void; + + /** + * Use this to manually fire an event handler that you created for a specific text or number field to be executed on the keypress event. + */ + fireOnKeyPress(): void; + /** * Gets the latest value in a control as the user types characters in a specific text or number field. * This method helps you to build interactive experiences by validating data and alerting users as they type characters in a control. @@ -2261,7 +1790,15 @@ declare namespace Xrm * Hides the auto-completion drop-down list configured for a specific text field */ hideAutoComplete(): void; - + + /** + * Use this to remove an event handler for a text or number field that you added using addOnKeyPress. + * + * Remarks: If an anonymous function is set using addOnKeyPress, it can’t be removed using this method. + * @param {ContextSensitiveHandler} handler The function reference. + */ + removeOnKeyPress(handler: ContextSensitiveHandler): void; + /** * Shows upt to 10 matching strings in a drop-down list as users press keys to type charactrer in a specific text field. * On selecting an item in the drop-down list, the value in the text field changes to the selected item, the drop-down list disappears, and the OnChange event for the text field is invoked @@ -2270,36 +1807,6 @@ declare namespace Xrm showAutoComplete(resultSet: AutoCompleteResultSet): void; } - /** - * Interface for a String control. - * - * @sa StandardControl - */ - export interface StringControl extends AutoLookupControl - { - /** - * Gets the control's bound attribute. - * - * @return The attribute. - */ - getAttribute(): StringAttribute; - } - - /** - * Interface for a Number control. - * - * @sa StandardControl - */ - export interface NumberControl extends AutoLookupControl - { - /** - * Gets the control's bound attribute. - * - * @return The attribute. - */ - getAttribute(): NumberAttribute; - } - /** * Interface for a Date control. * @@ -2603,7 +2110,7 @@ declare namespace Xrm * @sa UiElement * @sa UiFocusable */ - export interface Tab extends UiStandardElement, UiFocusable + export interface Tab extends UiElement, UiFocusable { /** * Gets display state of the tab. @@ -2644,7 +2151,7 @@ declare namespace Xrm * * @sa UiElement */ - export interface Section extends UiStandardElement + export interface Section extends UiElement { /** * Gets the name of the section. @@ -2676,14 +2183,14 @@ declare namespace Xrm */ export type FormNotificationLevel = "ERROR" | "INFO" | "WARNING"; - /** + /** * Display States for Xrm.ui.ProcessMonitor.setDisplayState(). - */ + */ export type DisplayState = "collapsed" | "expanded"; - /** + /** * Interface for Xrm.Page.ui.process API - */ + */ export interface ProcessManager { /** @@ -2691,7 +2198,7 @@ declare namespace Xrm * * @param {string} displayState Display state of the process flow control, as either "expanded" or "collapsed" */ - setDisplayState( displayState: ui.DisplayState ): void; + setDisplayState(displayState: ui.DisplayState ): void; /** * Sets the visibility state. @@ -2823,7 +2330,7 @@ declare namespace Xrm } /** - * Interface for a view selector item. This object contains data that identifies a view. Use this as a parameter to + * Interface for a view selector item. This object contains data that identifies a view. Use this as a parameter to * the ViewSelector.setCurrentView method. */ export interface ViewSelectorItem @@ -2835,93 +2342,6 @@ declare namespace Xrm */ getEntityReference(): LookupValue; } - - /** - * Interface for a quick view control instance on a form. - * - * @see {@link https://msdn.microsoft.com/en-us/library/mt736908.aspx#bkmk_isLoaded} for details. - */ - export interface QuickForm extends Control, UiLabelElement, UiCanGetVisibleElement - { - /** - * Gets the constituent controls in a quick view control. - * - * @return An array of controls. - * - * @remarks Constituent controls in a quick view control are read only. - */ - getControl(): Page.Control[]; - - /** - * Gets the constituent controls in a quick view control. - * - * @tparam T A Control type - * @param {string} controlName Name of the control. - * - * @return The control. - * - * @remarks Constituent controls in a quick view control are read only. - */ - getControl( controlName: string ): T; - - /** - * Gets the constituent controls in a quick view control. - * - * @param {string} controlName Name of the control. - * - * @return The control. - * - * @remarks Constituent controls in a quick view control are read only. - */ - getControl( controlName: string ): Page.Control; - - /** - * Gets a control by index. - * - * @tparam T A Control type - * @param {number} index The control index. - * - * @return The control. - * - * @remarks Constituent controls in a quick view control are read only. - */ - getControl( index: number ): T; - - /** - * Gets a control by index. - * - * @param {number} index The control index. - * - * @return The control. - * - * @remarks Constituent controls in a quick view control are read only. - */ - getControl( index: number ): Page.Control; - - /** - * Gets the controls type. - * - * @return Returns a string value that categorizes quick view controls. - */ - getControlType(): "quickform"; - - /** - * Returns whether the data binding for the constituent controls in a quick view control is complete. - * - * @return True is the data binding for a constituent control is complete, otherwise false. - * because the quick view form that the control is bound to may not have loaded completely. - * As a result, using the getAttribute or any data-related methods on a constituent control might not work. - * The isLoaded method for the quick view control helps determine the data binding status for constituent controls in a quick view control. - * - * @remarks The data binding for the constituent controls in a quick view control may not be complete during the main form OnLoad event - */ - isLoaded(): boolean; - - /** - * Refreshes the data displayed in a quick view control. - */ - refresh(): void; - } } /** @@ -2930,7 +2350,7 @@ declare namespace Xrm * @sa UiElement * @sa UiFocusable */ - export interface NavigationItem extends UiStandardElement, UiFocusable + export interface NavigationItem extends UiElement, UiFocusable { /** * Gets the name of the item. @@ -3007,13 +2427,11 @@ declare namespace Xrm /** * Command Bar Display options for Xrm.Url.FormOpenParameters.cmdbar, Xrm.Url.ViewOpenParameters.cmdbar, and Xrm.Utility.FormOpenParameters.cmdbar. */ - export type CmdBarDisplay = "true" | "false"; /** * Navigation Bar Display options for Xrm.Url.FormOpenParameters.navbar, Xrm.Url.ViewOpenParameters.navbar, and Xrm.Utility.FormOpenParameters.navbar. */ export type NavBarDisplay = "entity" | "off" | "on"; - /** * Report Open Action options for Xrm.Url.ReportOpenParameters.actions. */ diff --git a/xrm/xrm-tests.ts b/xrm/xrm-tests.ts index 56d8f32b3c..1893b9b89a 100644 --- a/xrm/xrm-tests.ts +++ b/xrm/xrm-tests.ts @@ -75,8 +75,7 @@ Xrm.Utility.openQuickCreate("account").then(( object ) => { if (object) alert( ` /// Make all controls visible. -// Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); }); // No longer works -Xrm.Page.ui.controls.forEach((control: Xrm.Page.StandardControl) => { control.setVisible(true); }); // Must cast to StandardControl +Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); }); /// Make all tabs and sections visible. @@ -167,28 +166,4 @@ autoCompleteControl.hideAutoComplete(); -/// Demonstrate v8.2 quick form controls - -const quickForm = Xrm.Page.ui.quickForms.get(0); -quickForm.getControlType(); // == "quickform" -quickForm.getName(); -quickForm.getParent(); -quickForm.getVisible(); // From UiCanSetVisibleElement -quickForm.getLabel(); // From UiLabelElement -quickForm.setLabel("Label"); // From UiLabelElement -quickForm.refresh(); - -// Get standard control -const ctrl = Xrm.Page.getControl("controlName"); -ctrl.getControlType() -ctrl.getName(); -ctrl.getParent(); -ctrl.getLabel(); -ctrl.setLabel("Label name"); -ctrl.getVisible(); -ctrl.setVisible(true); - - - - From 0c3a0003e1858ece009bc33f93e25cd2c6970886 Mon Sep 17 00:00:00 2001 From: clownwilleatme Date: Tue, 7 Feb 2017 10:34:09 +1100 Subject: [PATCH 3/9] Adding XRM v8.2 --- xrm/index.d.ts | 836 ++++++++++++++++++++++++++++++++++++++++------- xrm/xrm-tests.ts | 26 +- 2 files changed, 734 insertions(+), 128 deletions(-) diff --git a/xrm/index.d.ts b/xrm/index.d.ts index 36bd556c13..01c627f33d 100644 --- a/xrm/index.d.ts +++ b/xrm/index.d.ts @@ -93,7 +93,7 @@ declare namespace Xrm * Gets a control matching controlName. * * @tparam T A Control type - * @param {string} controlName Name of the control. + * @param {string} controlName Name of the control. * * @return The control. */ @@ -102,12 +102,22 @@ declare namespace Xrm /** * Gets a control matching controlName. * - * @param {string} controlName Name of the control. + * @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. * @@ -166,11 +176,10 @@ declare namespace Xrm * @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; + openQuickCreate( entityLogicalName: string, createFromEntity?: Page.LookupValue, parameters?: Utility.OpenParameters ): + Async.XrmPromise; /** * Opens an entity form. @@ -205,16 +214,194 @@ declare namespace Xrm */ openWebResource( webResourceName: string, webResourceData?: string, width?: number, height?: number ): Window; } + + /** + * Provides methods to create and manage records in the mobile clients (for phones tablets). + */ + Mobile: { + /** + * Provides methods to create and manage records in the mobile clients while working in the offline mode. + * + * @see {@link https://msdn.microsoft.com/en-us/library/mt787123.aspx} for details. + */ + offline: { + /** + * Returns whether an entity is offline enabled. + * + * @param {string} entityType The logical name of the entity. + * + * @return {boolean} True if the entity is offline enabled; otherwise False. + */ + isOfflineEnabled( entityType: string ): boolean; + + /** + * Creates an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {Object} data A dictionary object containing key : value pairs for the record to create. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot create intersect and activity party entities. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + createRecord( entityType: string, data: { [attributeName: string]: any } ): Async.XrmPromise; + + /** + * Retrieves an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to retrieve. + * @param {string} options (Optional) OData system query options to retrieve your data. Supports $select and $expand + * Example: ?$select=name&$expand=primarycontactid($select=contactid,fullname) + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks Only $select option can be specified within $expand. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + retrieveRecord( entityType: string, id: string, options: string ): Async.XrmPromise; + + /** + * Retrieves a collection of entity records in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} options (Optional) The logical name of the enti + * @param {string} maxPageSize (Optional) A positive number to indicates the number of entity records to be returned per page. + * If you do not specify this parameter, the default value is passed as 5000. + * If the number of records being retrieved is more than maxPageSize, an @odata.nextLink property + * will be returned, and you can use the value of the @odata.nextLink property with a new GET + * request to return next set of records. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks A maximum of 5000 related records can be retrieved when using $expand. + * Only $select option can be specified within $expand. + * $skip query option is not supported. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + retrieveMultipleRecords( entityType: string, options: string, maxPageSize: number ): Async.XrmPromise; + + /** + * Updates an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to update. + * @param {Object} data A dictionary object containing key : value pairs for the record to update. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot update intersect and activity party entities. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + updateRecord( entityType: string, id: string, data: { [attributeName: string]: any } ): Async.XrmPromise; + + /** + * Deletes an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to delete. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot delete intersect and activity party entities. + */ + deleteRecord( entityType: string, id: string ): Async.XrmPromise; + } + } + + /** + * Provides methods to display a web page in the side pane of web client. + * + * @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; + } } /** * Client Types for Xrm.Page.context.getClient(). */ export type Client = "Web" | "Outlook" | "Mobile"; + /** * Client States for Xrm.Page.context.getClientState(). */ export type ClientState = "Online" | "Offline"; + /** * Themes for Xrm.Page.context.getCurrentTheme(). */ @@ -254,6 +441,7 @@ declare namespace Xrm * Gets client's base URL for Dynamics CRM * * @return The client's base URL + * * @remarks For Dynamics CRM On-Premises: http(s)://server/org * For Dynamics CRM Online: https://org.crm.dynamics.com * For Dynamics CRM for Outlook (Offline): http://localhost:2525 @@ -354,6 +542,20 @@ declare namespace Xrm prependOrgName( sPath: string ): string; } + /** + * Defines save options to control how appointment, recurring appointment, or service activity records are processed. + * + * @see {@link https://msdn.microsoft.com/en-us/library/dn481607.aspx#Anchor_2} for details. + */ + interface SaveOptions + { + /** + * Indicates whether to use the Book or Reschedule messages rather than the Create or Update messages. + * Applicable to appointment, recurring appointment, or service activity records. + */ + UseSchedulingEngine?: boolean; + } + /** * Interface for the Xrm.Page.data object. */ @@ -364,16 +566,25 @@ declare namespace Xrm * * @param {boolean} save true to save the record, after the refresh. * - * @return An Async.XrmPromise. + * @return {Async.XrmPromise} Returns an asynchronous promise. */ - refresh( save: boolean ): Async.XrmPromise; + refresh( save: boolean ): Async.XrmPromise; /** * Asynchronously saves the record. * - * @return An Async.XrmPromise. + * @return {Async.XrmPromise} Returns an asynchronous promise. */ - save(): Async.XrmPromise; + save(): Async.XrmPromise; + + /** + * Asynchronously saves the record with the option to set callback functions to be executed after the save operation is completed. + * + * @param {saveOptions} saveOptions Options to control how appointment, recurring appointment, or service activity records are processed. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + */ + save( saveOptions: SaveOptions ): Async.XrmPromise; /** * The record context of the form. @@ -393,12 +604,28 @@ declare namespace Xrm */ export interface Ui { + /** + * Displays a form level notification. Any number of notifications can be displayed and will remain until removed using clearFormNotification. + * The height of the notification area is limited so each new message will be added to the top. + * + * @param {string} message The text of the notification message. + * @param {Page.ui.FormNotificationLevel} level The level of the notification which defines how the message will be displayed, such as the icon. + * @param {string} uniqueId Unique identifier for the notification which is used with clearFormNotification to remove the notification. + * + * @return true if it succeeds, otherwise false. + * + * @remarks Values for level are: ERROR Notification will use the system error icon. + * WARNING Notification will use the system warning icon. + * INFO Notification will use the system info icon. + */ + setFormNotification( message: string, level: Page.ui.FormNotificationLevel | string, uniqueId: string ): boolean; + /** * Clears the form notification described by uniqueId. * * @param {string} uniqueId Unique identifier. * - * @return true if it succeeds, otherwise false. + * @return True if it succeeds, otherwise false. */ clearFormNotification( uniqueId: string ): boolean; @@ -441,14 +668,15 @@ declare namespace Xrm getViewPortWidth(): number; /** - * Re-evaluates the ribbon's configured EnableRules + * Re-evaluates the ribbon's configured EnableRules. * * @remarks This method does not work with Microsoft Dynamics CRM for tablets. */ refreshRibbon(): void; - setFormNotification(message: string, level: Page.ui.FormNotificationLevel | string, uniqueId: string ): boolean; - + /** + * The business process flow API, used to interact with the business process flow control in a form. + */ process: Page.ui.ProcessManager; /** @@ -474,6 +702,11 @@ declare namespace Xrm * A reference to the collection of tabs on the form. */ tabs: Collection.ItemCollection; + + /** + * A collection of all the quick view controls on a form using the new form rendering engine (also called "turbo forms"). + */ + quickForms: Collection.ItemCollection; } /** @@ -481,38 +714,115 @@ declare namespace Xrm */ export module Async { - /** - * Object passed to ErrorCallbackDelegate - */ - export interface ErrorCallbackObject - { - errorCode: number; - message: string; - } - - export interface SuccessCallbackObject - { - savedEntityReference: Page.LookupValue; - } - /** * Called when the operation is successful. - * Currently, only the Xrm.Utility.openQuickCreate successCallback - * is passed a parameter so an optional parameter for it is included */ - export type SuccessCallbackDelegate = (object?: SuccessCallbackObject ) => void; - + export type SuccessCallbackDelegate = () => void; + /** * Called when the operation fails. * - * @param {ErrorCallbackObject} error The error object + * @param {ErrorCallbackObject} error The error object. */ export type ErrorCallbackDelegate = ( error: ErrorCallbackObject ) => void; /** - * Interface for Xrm.Page.data promises. + * Called when the Xrm.Utility.openQuickCreate operation is successful and a new record has been created. + * + * @param {OpenQuickCreateSuccessCallbackObject} record An object which contains a lookup value which identifies the record which has been created. + * + * @see {Xrm.Utility.openQuickCreate} */ - export interface XrmPromise + export type QuickCreateSuccessCallbackDelegate = ( record: OpenQuickCreateSuccessCallbackObject ) => void; + + /** + * Called when the offline operation is successful. + * + * @param {OfflineOperationSuccessCallbackObject} record The record returned from the operation. + * + * @see {Xrm.Mobile.offline} + */ + export type OfflineOperationSuccessCallbackDelegate = ( record: OfflineOperationSuccessCallbackObject ) => void; + + /** + * Called when the offline retrieve multiple operation is successful. + * + * @param {OfflineRetrieveMultipleSuccessCallbackDelegate} resultSet The dictionary of records retrieved from the operation. + * + * @see {Xrm.Mobile.offline.retrieveMultipleRecords} + */ + export type OfflineRetrieveMultipleSuccessCallbackDelegate = (resultSet: { [key: string]: any }[]) => void; + + /** + * Called when the operation fails. + * + * @param {OfflineErrorCallbackObject} error The error object. + * + * @see {Xrm.Mobile.offline} + */ + export type OfflineErrorCallbackDelegate = (error: OfflineErrorCallbackObject) => void; + + + /** + * Object passed to ErrorCallbackDelegate. + */ + export interface ErrorCallbackObject + { + /** + * The error code. + */ + errorCode: number; + + /** + * An error message describing the issue. + */ + message: string; + } + + /** + * Object passed to QuickCreateSuccessCallbackDelegate. + */ + export interface OpenQuickCreateSuccessCallbackObject + { + /** + * A lookup value which identifies the record which has been created. + */ + savedEntityReference: Page.LookupValue; + } + + /** + * Object passed to OfflineOperationSuccessCallbackDelegate; + */ + export interface OfflineOperationSuccessCallbackObject + { + /** + * GUID of the record; + */ + id: string; + /** + * Logical name of the entity. + */ + logicalName: string; + } + + /** + * Object passed to OfflineErrorCallbackDelegate. + */ + export interface OfflineErrorCallbackObject extends ErrorCallbackObject + { + /** + * An internal error message that might contain additional details about the issue. + */ + debugMessage: string; + } + + /** + * Interface for asynchronous promises used in Xrm.Page.data and Xrm.Utility.openQuickCreate. + * + * @tparam TSuccessCallback Generic success callback parameter. + * @tparam TErrorCallback Generic error callback parameter. + */ + export interface XrmPromise { /** * A basic 'then' promise. @@ -520,7 +830,7 @@ declare namespace Xrm * @param {SuccessCallbackDelegate} successCallback The success callback. * @param {ErrorCallbackDelegate} errorCallback The error callback. */ - then( successCallback: SuccessCallbackDelegate, errorCallback: ErrorCallbackDelegate ): void; + then( successCallback: TSuccessCallback, errorCallback: TErrorCallback ): void; } } @@ -633,19 +943,57 @@ declare namespace Xrm * Requirement Level for Xrm.Page.Attribute.getRequiredLevel() and Xrm.Page.Attribute.setRequiredLevel(). */ export type RequirementLevel = "none" | "recommended" | "required"; + /** * Save Modes for Xrm.Page.Entity.save(). */ export type SaveMode = "saveandclose" | "saveandnew"; + /** * Status for Xrm.Page.Stage.getStatus(). */ export type Status = "active" | "inactive"; + /** * Submit Mode for Xrm.Page.Attribute.getSubmitMode() and Xrm.Page.Attribute.setSubmitMode(). */ export type SubmitMode = "always" | "dirty" | "never"; + + /** + * Control types for Xrm.Page.Control.getControlType(). + */ + export type ControlType = "standard" | "iframe" | "lookup" | "optionset" | "subgrid" | "webresource" | "notes" | "timercontrol" | "kbsearch" | "quickform"; + /** + * Date attribute formats for Xrm.Page.Attribute.getFormat(), used by DateAttribute. + */ + export type DateAttributeFormat = "date" | "datetime"; + + /** + * Integer attribute formats for Xrm.Page.Attribute.getFormat(), used by NumberAttribute. + */ + export type IntegerAttributeFormat = "duration" | "none"; + + /** + * OptionSet attribute formats for Xrm.Page.Attribute.getFormat(), used by OptionSetAttribute. + */ + export type OptionSetAttributeFormat = "language" | "timezone"; + + /** + * String attribute formats for Xrm.Page.Attribute.getFormat(), used by StringAttribute. + */ + export type StringAttributeFormat = "email" | "phone" | "text" | "textarea" | "tickersymbol" | "url"; + + /** + * Attribute types for Xrm.ui.ProcessMonitor Xrm.Page.Attribute.setDisplayState(). + */ + export type AttributeType = "boolean" | "datetime" | "decimal" | "double" | "integer" | "lookup" | "memo" | "money" | "optionset" | "string"; + + /** + * Attribute formats for Xrm.Page.Attribute.getFormat(). + */ + export type AttributeFormat = DateAttributeFormat | IntegerAttributeFormat | OptionSetAttributeFormat | StringAttributeFormat; + /** * Interface for a CRM Business Process Flow instance. */ @@ -836,9 +1184,9 @@ declare namespace Xrm } /** - * Base interface for UI elements. + * Interface for UI elements with labels. */ - export interface UiElement + export interface UiLabelElement { /** * Gets the label. @@ -846,21 +1194,33 @@ declare namespace Xrm * @return The label. */ getLabel(): string; - - /** - * Gets the visibility state. - * - * @return true if the tab is visible, otherwise false. - */ - getVisible(): boolean; - + /** * Sets the label. * * @param {string} label The label. */ setLabel( label: string ): void; + } + /** + * Interface for UI elements which can have the visibility value read. + */ + export interface UiCanGetVisibleElement + { + /** + * Gets the visibility state. + * + * @return true if the tab is visible, otherwise false. + */ + getVisible(): boolean; + } + + /** + * Base interface for standard UI elements. + */ + export interface UiStandardElement extends UiCanGetVisibleElement, UiLabelElement + { /** * Sets the visibility state. * @@ -879,15 +1239,44 @@ declare namespace Xrm */ setFocus(): void; } + + /** + * Interface for controls which methods provide immediate feedback or take actions as user types in a control. + * Contains methods which can be used to perform data validations in a control even before the user commits (saves) the value in a form. + */ + export interface UiKeyPressable + { + /** + * Use this to add a function as an event handler for the keypress event so that the function is called when you type a character in the specific text or number field. + * For a sample JavaScript code that uses the addOnKeyPress method to configure the auto-completion experience, see Sample: Auto-complete in CRM controls. + * + * @param {ContextSensitiveHandler} handler The function reference. + */ + addOnKeyPress( handler: ContextSensitiveHandler ): void; + + /** + * Use this to manually fire an event handler that you created for a specific text or number field to be executed on the keypress event. + */ + fireOnKeyPress(): void; + + /** + * Use this to remove an event handler for a text or number field that you added using addOnKeyPress. + * + * Remarks: If an anonymous function is set using addOnKeyPress, it can’t be removed using this method. + * @param {ContextSensitiveHandler} handler The function reference. + */ + removeOnKeyPress( handler: ContextSensitiveHandler ): void; + } /** * Interface for Result value of AutoCompleteResultSet */ - export interface AutoCompleteResult { + export interface AutoCompleteResult + { /** * The Identifier */ - id: string|number; + id: string | number; /** * Url of the icon to display @@ -903,7 +1292,8 @@ declare namespace Xrm /** * Interface for command of AutoCompleteResultSet. This is displayed at the bottom of the auto complete view */ - export interface AutoCompleteCommand { + export interface AutoCompleteCommand + { /** * The Identifier */ @@ -928,7 +1318,8 @@ declare namespace Xrm /** * Interface for showAutoComplete argument */ - export interface AutoCompleteResultSet { + export interface AutoCompleteResultSet + { /** * Results to show */ @@ -983,17 +1374,17 @@ declare namespace Xrm export interface Privilege { /** - * true if the user can read. + * True if the user can read. */ canRead: boolean; /** - * true if the user can update. + * True if the user can update. */ canUpdate: boolean; /** - * true if the user can create. + * True if the user can create. */ canCreate: boolean; } @@ -1032,7 +1423,7 @@ declare namespace Xrm * string */ getAttributeType(): string; - + /** * Gets the attribute format. * @@ -1053,7 +1444,7 @@ declare namespace Xrm * timezone (optionset) * url (string) */ - getFormat(): string; + getFormat(): AttributeFormat; /** * Gets a boolean value indicating whether this Attribute has unsaved changes. @@ -1111,7 +1502,7 @@ declare namespace Xrm * * @param {string} requirementLevel The requirement level, as either "none", "required", or "recommended" */ - setRequiredLevel(requirementLevel: RequirementLevel | string): void; + setRequiredLevel( requirementLevel: RequirementLevel | string ): void; /** * Sets the submit mode. @@ -1120,12 +1511,26 @@ declare namespace Xrm * * @remarks The default value is "dirty" */ - setSubmitMode(submitMode: SubmitMode | string): void; + setSubmitMode( submitMode: SubmitMode | string ): void; /** * A collection of all the controls on the form that interface with this attribute. */ controls: Collection.ItemCollection; + + /** + * Gets the value. + * + * @return The value. + */ + getValue(): any; + + /** + * Sets the value. + * + * @param {any} value The value. + */ + setValue( value: any ): void; } /** @@ -1135,6 +1540,16 @@ declare namespace Xrm */ export interface NumberAttribute extends Attribute { + /** + * Gets the attribute format. + * + * @return The format of the attribute. + * + * @remarks Values returned are: duration + * none + */ + getFormat(): IntegerAttributeFormat; + /** * Gets the maximum value allowed. * @@ -1171,6 +1586,11 @@ declare namespace Xrm * @remarks Attributes on Quick Create Forms will not save values set with this method. */ setValue( value: number ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; } /** @@ -1180,6 +1600,20 @@ declare namespace Xrm */ export interface StringAttribute extends Attribute { + /** + * Gets the attribute format. + * + * @return The format of the attribute. + * + * @remarks Values returned are: email + * phone + * text + * textarea + * tickersymbol + * url + */ + getFormat(): StringAttributeFormat; + /** * Gets maximum length allowed. * @@ -1206,6 +1640,11 @@ declare namespace Xrm * with this method. */ setValue( value: string ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; } /** @@ -1219,7 +1658,8 @@ declare namespace Xrm * Gets the initial value of the attribute. * * @return The initial value. - * @remarks Valid for optionset and boolean attribute types + * + * @remarks Valid for OptionSet and boolean attribute types */ getInitialValue(): number | boolean; } @@ -1255,6 +1695,16 @@ declare namespace Xrm */ export interface DateAttribute extends Attribute { + /** + * Gets the attribute format. + * + * @return The format of the attribute. + * + * @remarks Values returned are: date + * datetime + */ + getFormat(): DateAttributeFormat; + /** * Gets the value. * @@ -1270,6 +1720,11 @@ declare namespace Xrm * @remarks Attributes on Quick Create Forms will not save values set with this method. */ setValue( value: Date ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; } /** @@ -1279,6 +1734,16 @@ declare namespace Xrm */ export interface OptionSetAttribute extends EnumAttribute { + /** + * Gets the attribute format. + * + * @return The format of the attribute. + * + * @remarks Values returned are: language + * timezone + */ + getFormat(): OptionSetAttributeFormat; + /** * Gets the option matching a value. * @@ -1336,6 +1801,11 @@ declare namespace Xrm * with this method. */ setValue( value: number ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; } /** @@ -1367,6 +1837,11 @@ declare namespace Xrm * @remarks Attributes on Quick Create Forms will not save values set with this method. */ setValue( value: LookupValue[] ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; } /** @@ -1464,6 +1939,7 @@ declare namespace Xrm * Gets save mode, as an integer. * * @return The save mode. + * * @remarks Values returned are: 1 Save * 2 Save and Close * 59 Save and New @@ -1488,6 +1964,7 @@ declare namespace Xrm /** * Prevents the save operation from being submitted to the server. + * * @remarks All remaining "on save" handlers will continue execution. */ preventDefault(): void; @@ -1631,6 +2108,7 @@ declare namespace Xrm * Called when process change methods have completed. * * @param {string} status The result of the process change operation. + * * @remarks Values returned are: success (The operation succeeded.) * crossEntity (The previous stage is for a different entity.) * beginning (The active stage is the first stage of the active path.) @@ -1645,29 +2123,19 @@ declare namespace Xrm */ export type ProcessDictionary = { [index: string]: string }; } - + /** * Interface for Xrm.Page.ui controls. * * @sa UiElement */ - export interface Control extends UiElement, UiFocusable + export interface Control extends UiLabelElement, UiCanGetVisibleElement { /** - * Clears the notification identified by uniqueId. - * - * @param {string} uniqueId (Optional) Unique identifier. - * - * @return true if it succeeds, false if it fails. - * - * @remarks If the uniqueId parameter is not used, the current notification shown will be removed. - */ - clearNotification( uniqueId?: string ): boolean; - - /** - * Gets the control's type. + * Gets the controls type. * * @return The control type. + * * @remarks Values returned are: standard * iframe * lookup @@ -1677,16 +2145,12 @@ declare namespace Xrm * notes * timercontrol * kbsearch (CRM Online Only, use parature.d.ts) + * quickform (see ui.QuickForm) + * customcontrol: . (A custom control for mobile phone and tablet clients). + * customsubgrid: . (A custom dataset control for mobile phone and tablet clients). */ - getControlType(): string; - - /** - * Gets a boolean value, indicating whether the control is disabled. - * - * @return true if it is disabled, otherwise false. - */ - getDisabled(): boolean; - + getControlType(): ControlType | string; + /** * Gets the name of the control on the form. * @@ -1711,7 +2175,33 @@ declare namespace Xrm * @return The parent Section. */ getParent(): Section; - + } + + /** + * Interface for a standard control. + * + * @sa Control + */ + export interface StandardControl extends Control, UiStandardElement, UiFocusable + { + /** + * Clears the notification identified by uniqueId. + * + * @param {string} uniqueId (Optional) Unique identifier. + * + * @return true if it succeeds, false if it fails. + * + * @remarks If the uniqueId parameter is not used, the current notification shown will be removed. + */ + clearNotification( uniqueId?: string ): boolean; + + /** + * Gets a boolean value, indicating whether the control is disabled. + * + * @return true if it is disabled, otherwise false. + */ + getDisabled(): boolean; + /** * Sets the state of the control to either enabled, or disabled. * @@ -1731,15 +2221,7 @@ declare namespace Xrm * appears next to the control. Tapping on the icon will display the message. */ setNotification( message: string, uniqueId: string ): boolean; - } - /** - * Interface for a standard control. - * - * @sa Control - */ - export interface StandardControl extends Control - { /** * Gets the control's bound attribute. * @@ -1756,28 +2238,17 @@ declare namespace Xrm */ getAttribute(): Attribute; } - + /** - * Interace for Auto Lookup Control - * This is not an Entity Lookup, but a control that supports AutoComplete/KeyPress Events (Text) - * NOTE * This interface is not supported for CRM mobile clients (phones or tablets) and the interactive service hub. It is only available for Updated entities. + * Interface for Auto Lookup Control. + * This is not an Entity Lookup, but a control that supports AutoComplete / KeyPress Events (Text or Number) + * + * @remarks This interface is not supported for CRM mobile clients (phones or tablets) and the interactive service hub. It is only available for Updated entities. * * @sa StandardControl */ - export interface AutoLookupControl extends StandardControl { - /** - * Use this to add a function as an event handler for the keypress event so that the function is called when you type a character in the specific text or number field. - * For a sample JavaScript code that uses the addOnKeyPress method to configure the auto-completion experience, see Sample: Auto-complete in CRM controls. - * - * @param {ContextSensitiveHandler} handler The function reference. - */ - addOnKeyPress(handler: ContextSensitiveHandler): void; - - /** - * Use this to manually fire an event handler that you created for a specific text or number field to be executed on the keypress event. - */ - fireOnKeyPress(): void; - + export interface AutoLookupControl extends StandardControl, UiKeyPressable + { /** * Gets the latest value in a control as the user types characters in a specific text or number field. * This method helps you to build interactive experiences by validating data and alerting users as they type characters in a control. @@ -1790,15 +2261,7 @@ declare namespace Xrm * Hides the auto-completion drop-down list configured for a specific text field */ hideAutoComplete(): void; - - /** - * Use this to remove an event handler for a text or number field that you added using addOnKeyPress. - * - * Remarks: If an anonymous function is set using addOnKeyPress, it can’t be removed using this method. - * @param {ContextSensitiveHandler} handler The function reference. - */ - removeOnKeyPress(handler: ContextSensitiveHandler): void; - + /** * Shows upt to 10 matching strings in a drop-down list as users press keys to type charactrer in a specific text field. * On selecting an item in the drop-down list, the value in the text field changes to the selected item, the drop-down list disappears, and the OnChange event for the text field is invoked @@ -1807,6 +2270,36 @@ declare namespace Xrm showAutoComplete(resultSet: AutoCompleteResultSet): void; } + /** + * Interface for a String control. + * + * @sa StandardControl + */ + export interface StringControl extends AutoLookupControl + { + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): StringAttribute; + } + + /** + * Interface for a Number control. + * + * @sa StandardControl + */ + export interface NumberControl extends AutoLookupControl + { + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): NumberAttribute; + } + /** * Interface for a Date control. * @@ -2110,7 +2603,7 @@ declare namespace Xrm * @sa UiElement * @sa UiFocusable */ - export interface Tab extends UiElement, UiFocusable + export interface Tab extends UiStandardElement, UiFocusable { /** * Gets display state of the tab. @@ -2151,7 +2644,7 @@ declare namespace Xrm * * @sa UiElement */ - export interface Section extends UiElement + export interface Section extends UiStandardElement { /** * Gets the name of the section. @@ -2183,14 +2676,14 @@ declare namespace Xrm */ export type FormNotificationLevel = "ERROR" | "INFO" | "WARNING"; - /** + /** * Display States for Xrm.ui.ProcessMonitor.setDisplayState(). - */ + */ export type DisplayState = "collapsed" | "expanded"; - /** + /** * Interface for Xrm.Page.ui.process API - */ + */ export interface ProcessManager { /** @@ -2198,7 +2691,7 @@ declare namespace Xrm * * @param {string} displayState Display state of the process flow control, as either "expanded" or "collapsed" */ - setDisplayState(displayState: ui.DisplayState ): void; + setDisplayState( displayState: ui.DisplayState ): void; /** * Sets the visibility state. @@ -2330,7 +2823,7 @@ declare namespace Xrm } /** - * Interface for a view selector item. This object contains data that identifies a view. Use this as a parameter to + * Interface for a view selector item. This object contains data that identifies a view. Use this as a parameter to * the ViewSelector.setCurrentView method. */ export interface ViewSelectorItem @@ -2342,6 +2835,93 @@ declare namespace Xrm */ getEntityReference(): LookupValue; } + + /** + * Interface for a quick view control instance on a form. + * + * @see {@link https://msdn.microsoft.com/en-us/library/mt736908.aspx#bkmk_isLoaded} for details. + */ + export interface QuickForm extends Control, UiLabelElement, UiCanGetVisibleElement + { + /** + * Gets the constituent controls in a quick view control. + * + * @return An array of controls. + * + * @remarks Constituent controls in a quick view control are read only. + */ + getControl(): Page.Control[]; + + /** + * Gets the constituent controls in a quick view control. + * + * @tparam T A Control type + * @param {string} controlName Name of the control. + * + * @return The control. + * + * @remarks Constituent controls in a quick view control are read only. + */ + getControl( controlName: string ): T; + + /** + * Gets the constituent controls in a quick view control. + * + * @param {string} controlName Name of the control. + * + * @return The control. + * + * @remarks Constituent controls in a quick view control are read only. + */ + getControl( controlName: string ): Page.Control; + + /** + * Gets a control by index. + * + * @tparam T A Control type + * @param {number} index The control index. + * + * @return The control. + * + * @remarks Constituent controls in a quick view control are read only. + */ + getControl( index: number ): T; + + /** + * Gets a control by index. + * + * @param {number} index The control index. + * + * @return The control. + * + * @remarks Constituent controls in a quick view control are read only. + */ + getControl( index: number ): Page.Control; + + /** + * Gets the controls type. + * + * @return Returns a string value that categorizes quick view controls. + */ + getControlType(): "quickform"; + + /** + * Returns whether the data binding for the constituent controls in a quick view control is complete. + * + * @return True is the data binding for a constituent control is complete, otherwise false. + * because the quick view form that the control is bound to may not have loaded completely. + * As a result, using the getAttribute or any data-related methods on a constituent control might not work. + * The isLoaded method for the quick view control helps determine the data binding status for constituent controls in a quick view control. + * + * @remarks The data binding for the constituent controls in a quick view control may not be complete during the main form OnLoad event + */ + isLoaded(): boolean; + + /** + * Refreshes the data displayed in a quick view control. + */ + refresh(): void; + } } /** @@ -2350,7 +2930,7 @@ declare namespace Xrm * @sa UiElement * @sa UiFocusable */ - export interface NavigationItem extends UiElement, UiFocusable + export interface NavigationItem extends UiStandardElement, UiFocusable { /** * Gets the name of the item. @@ -2427,11 +3007,13 @@ declare namespace Xrm /** * Command Bar Display options for Xrm.Url.FormOpenParameters.cmdbar, Xrm.Url.ViewOpenParameters.cmdbar, and Xrm.Utility.FormOpenParameters.cmdbar. */ + export type CmdBarDisplay = "true" | "false"; /** * Navigation Bar Display options for Xrm.Url.FormOpenParameters.navbar, Xrm.Url.ViewOpenParameters.navbar, and Xrm.Utility.FormOpenParameters.navbar. */ export type NavBarDisplay = "entity" | "off" | "on"; + /** * Report Open Action options for Xrm.Url.ReportOpenParameters.actions. */ @@ -2709,4 +3291,4 @@ declare namespace XrmEnum SystemView = 1039, UserView = 4230 } -} +} \ No newline at end of file diff --git a/xrm/xrm-tests.ts b/xrm/xrm-tests.ts index 1893b9b89a..fd371c94de 100644 --- a/xrm/xrm-tests.ts +++ b/xrm/xrm-tests.ts @@ -75,7 +75,8 @@ Xrm.Utility.openQuickCreate("account").then(( object ) => { if (object) alert( ` /// Make all controls visible. -Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); }); +// Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); }); // No longer works +Xrm.Page.ui.controls.forEach((control: Xrm.Page.StandardControl) => { control.setVisible(true); }); // Must cast to StandardControl /// Make all tabs and sections visible. @@ -166,4 +167,27 @@ autoCompleteControl.hideAutoComplete(); +/// Demonstrate v8.2 quick form controls + +const quickForm = Xrm.Page.ui.quickForms.get(0); +quickForm.getControlType(); // == "quickform" +quickForm.getName(); +quickForm.getParent(); +quickForm.getVisible(); // From UiCanSetVisibleElement +quickForm.getLabel(); // From UiLabelElement +quickForm.setLabel("Label"); // From UiLabelElement +quickForm.refresh(); + +// Get standard control +const ctrl = Xrm.Page.getControl("controlName"); +ctrl.getControlType() +ctrl.getName(); +ctrl.getParent(); +ctrl.getLabel(); +ctrl.setLabel("Label name"); +ctrl.getVisible(); +ctrl.setVisible(true); + + + From ff6194f4930bf11767ffc9f54a82f0c2a8968292 Mon Sep 17 00:00:00 2001 From: clownwilleatme Date: Tue, 7 Feb 2017 14:27:08 +1100 Subject: [PATCH 4/9] Xrm.Mobile.offline interface, string unions - Moving Xrm.Mobile and Xrm.Mobile.offline into interfaces. - Removing union string types for: - Xrm.Page.ui.setFormNotification - Xrm.Page.Attribute.setSubmitMode - Xrm.Page.data.entity.save - Xrm.Page.Attribute.setDisplayState --- xrm/index.d.ts | 336 +++++++++++++++++++++++++------------------------ 1 file changed, 175 insertions(+), 161 deletions(-) diff --git a/xrm/index.d.ts b/xrm/index.d.ts index 01c627f33d..821d7ff111 100644 --- a/xrm/index.d.ts +++ b/xrm/index.d.ts @@ -117,7 +117,7 @@ declare namespace Xrm * @return The control. */ getControl( index: number ): T; - + /** * Gets a control by index. * @@ -218,162 +218,8 @@ declare namespace Xrm /** * Provides methods to create and manage records in the mobile clients (for phones tablets). */ - Mobile: { - /** - * Provides methods to create and manage records in the mobile clients while working in the offline mode. - * - * @see {@link https://msdn.microsoft.com/en-us/library/mt787123.aspx} for details. - */ - offline: { - /** - * Returns whether an entity is offline enabled. - * - * @param {string} entityType The logical name of the entity. - * - * @return {boolean} True if the entity is offline enabled; otherwise False. - */ - isOfflineEnabled( entityType: string ): boolean; + Mobile: Mobile; - /** - * Creates an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {Object} data A dictionary object containing key : value pairs for the record to create. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks You cannot create intersect and activity party entities. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ - createRecord( entityType: string, data: { [attributeName: string]: any } ): Async.XrmPromise; - - /** - * Retrieves an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} id GUID of the record to retrieve. - * @param {string} options (Optional) OData system query options to retrieve your data. Supports $select and $expand - * Example: ?$select=name&$expand=primarycontactid($select=contactid,fullname) - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks Only $select option can be specified within $expand. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ - retrieveRecord( entityType: string, id: string, options: string ): Async.XrmPromise; - - /** - * Retrieves a collection of entity records in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} options (Optional) The logical name of the enti - * @param {string} maxPageSize (Optional) A positive number to indicates the number of entity records to be returned per page. - * If you do not specify this parameter, the default value is passed as 5000. - * If the number of records being retrieved is more than maxPageSize, an @odata.nextLink property - * will be returned, and you can use the value of the @odata.nextLink property with a new GET - * request to return next set of records. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks A maximum of 5000 related records can be retrieved when using $expand. - * Only $select option can be specified within $expand. - * $skip query option is not supported. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ - retrieveMultipleRecords( entityType: string, options: string, maxPageSize: number ): Async.XrmPromise; - - /** - * Updates an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} id GUID of the record to update. - * @param {Object} data A dictionary object containing key : value pairs for the record to update. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks You cannot update intersect and activity party entities. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ - updateRecord( entityType: string, id: string, data: { [attributeName: string]: any } ): Async.XrmPromise; - - /** - * Deletes an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} id GUID of the record to delete. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks You cannot delete intersect and activity party entities. - */ - deleteRecord( entityType: string, id: string ): Async.XrmPromise; - } - } - /** * Provides methods to display a web page in the side pane of web client. * @@ -618,7 +464,7 @@ declare namespace Xrm * WARNING Notification will use the system warning icon. * INFO Notification will use the system info icon. */ - setFormNotification( message: string, level: Page.ui.FormNotificationLevel | string, uniqueId: string ): boolean; + setFormNotification( message: string, level: Page.ui.FormNotificationLevel, uniqueId: string ): boolean; /** * Clears the form notification described by uniqueId. @@ -709,6 +555,174 @@ declare namespace Xrm quickForms: Collection.ItemCollection; } + /** + * Interface for methods to create and manage records in the mobile clients (for phones tablets). + */ + export interface Mobile + { + /** + * Provides methods to create and manage records in the mobile clients while working in the offline mode. + * + * @see {@link https://msdn.microsoft.com/en-us/library/mt787123.aspx} for details. + */ + offline: MobileOffline; + } + + /** + * Interface for the Mobile.offline methods to create and manage records in the mobile clients while working in the offline mode. + * + * @see {@link https://msdn.microsoft.com/en-us/library/mt787123.aspx} for details. + */ + export interface MobileOffline + { + /** + * Returns whether an entity is offline enabled. + * + * @param {string} entityType The logical name of the entity. + * + * @return {boolean} True if the entity is offline enabled; otherwise False. + */ + isOfflineEnabled( entityType: string ): boolean; + + /** + * Creates an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {Object} data A dictionary object containing key : value pairs for the record to create. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot create intersect and activity party entities. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + createRecord( entityType: string, data: { [attributeName: string]: any } ): Async.XrmPromise; + + /** + * Retrieves an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to retrieve. + * @param {string} options (Optional) OData system query options to retrieve your data. Supports $select and $expand + * Example: ?$select=name&$expand=primarycontactid($select=contactid,fullname) + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks Only $select option can be specified within $expand. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + retrieveRecord( entityType: string, id: string, options: string ): Async.XrmPromise; + + /** + * Retrieves a collection of entity records in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} options (Optional) The logical name of the enti + * @param {string} maxPageSize (Optional) A positive number to indicates the number of entity records to be returned per page. + * If you do not specify this parameter, the default value is passed as 5000. + * If the number of records being retrieved is more than maxPageSize, an @odata.nextLink property + * will be returned, and you can use the value of the @odata.nextLink property with a new GET + * request to return next set of records. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks A maximum of 5000 related records can be retrieved when using $expand. + * Only $select option can be specified within $expand. + * $skip query option is not supported. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + retrieveMultipleRecords( entityType: string, options: string, maxPageSize: number ): Async.XrmPromise; + + /** + * Updates an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to update. + * @param {Object} data A dictionary object containing key : value pairs for the record to update. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot update intersect and activity party entities. + * Only the following attribute types are supported in offline mode: BigInt + * Boolean + * Customer + * DateTime + * Decimal + * Double + * EntityName + * Integer + * Lookup + * Memo + * Money + * Owner + * Picklist + * String + * State + * Status + * UniqueIdentifier + */ + updateRecord( entityType: string, id: string, data: { [attributeName: string]: any } ): Async.XrmPromise; + + /** + * Deletes an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to delete. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot delete intersect and activity party entities. + */ + deleteRecord( entityType: string, id: string ): Async.XrmPromise; + } + /** * A definition module for asynchronous interface declarations. */ @@ -1502,7 +1516,7 @@ declare namespace Xrm * * @param {string} requirementLevel The requirement level, as either "none", "required", or "recommended" */ - setRequiredLevel( requirementLevel: RequirementLevel | string ): void; + setRequiredLevel( requirementLevel: RequirementLevel ): void; /** * Sets the submit mode. @@ -1511,7 +1525,7 @@ declare namespace Xrm * * @remarks The default value is "dirty" */ - setSubmitMode( submitMode: SubmitMode | string ): void; + setSubmitMode( submitMode: SubmitMode ): void; /** * A collection of all the controls on the form that interface with this attribute. @@ -1922,7 +1936,7 @@ declare namespace Xrm * @param {string} saveMode (Optional) the save mode to save, as either "saveandclose" or * "saveandnew". */ - save( saveMode: SaveMode | string): void; + save( saveMode: SaveMode ): void; /** * The collection of attributes for the record. @@ -2631,7 +2645,7 @@ declare namespace Xrm * * @param {string} displayState Display state of the tab, as either "expanded" or "collapsed" */ - setDisplayState(displayState: ui.DisplayState | string ): void; + setDisplayState(displayState: ui.DisplayState ): void; /** * A reference to the collection of form sections within this tab. From 892bc67f321c1db486862bb29a73bc9af4565b2f Mon Sep 17 00:00:00 2001 From: clownwilleatme Date: Tue, 7 Feb 2017 17:08:22 +1100 Subject: [PATCH 5/9] Modifying the unit test to fix errors Modify the unit test to set the string variables which are used for calls to attribute.setSubmitMode and attribute.setRequiredLevel to use const strings as strings declared as var or let fail. This is by design for string union types in TypeScript - see: https://github.com/Microsoft/TypeScript/issues/9489 --- xrm/xrm-tests.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xrm/xrm-tests.ts b/xrm/xrm-tests.ts index fd371c94de..1242236f36 100644 --- a/xrm/xrm-tests.ts +++ b/xrm/xrm-tests.ts @@ -124,15 +124,15 @@ Xrm.Page.ui.setFormNotification("Test", level, "uniqueId"); /// Demonstrate Requirement Level and Submit Mode both via string parameters and String Literal Types let requirementLevel: Xrm.Page.RequirementLevel = "none"; -let requirementLevelString = "none"; +const requirementLevelString = "none"; let submitMode: Xrm.Page.SubmitMode = "always"; -let submitModeString = "always"; +const submitModeString = "always"; let attribute = Xrm.Page.getAttribute("customerid"); attribute.setSubmitMode(submitMode); -attribute.setSubmitMode(submitMode); +attribute.setSubmitMode(submitModeString); // Works if the string is a const attribute.setRequiredLevel(requirementLevel); -attribute.setRequiredLevel(requirementLevelString); +attribute.setRequiredLevel(requirementLevelString); // Works if the string is a const /// Demonstrate v8 AutoComplete From 53f76553c0b0d6a002605a7b26b7dd2a6bfb49fb Mon Sep 17 00:00:00 2001 From: clownwilleatme Date: Wed, 8 Feb 2017 08:56:34 +1100 Subject: [PATCH 6/9] Updating API version number, adding TS version Updating the API version number from 8.0 to 8.2 Adding TypeScript version 2.1 to the header to allow the unit tests to compile using const string variables for attribute.setSubmitMode and attribute.setRequiredLevel methods with the removed string union. --- xrm/index.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xrm/index.d.ts b/xrm/index.d.ts index 821d7ff111..bbdd060c9f 100644 --- a/xrm/index.d.ts +++ b/xrm/index.d.ts @@ -1,7 +1,8 @@ -// Type definitions for Microsoft Dynamics xRM API v8.0 +// Type definitions for Microsoft Dynamics xRM API v8.2 // Project: http://www.microsoft.com/en-us/download/details.aspx?id=44567 -// Definitions by: David Berry , Matt Ngan , Markus Mauch , Daryl LaBar +// Definitions by: David Berry , Matt Ngan , Markus Mauch , Daryl LaBar , Tully H // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 declare var Xrm: Xrm.XrmStatic; declare function GetGlobalContext(): Xrm.Context; From f0f92d8cd89b20eae3f2e67c314b08a804a80475 Mon Sep 17 00:00:00 2001 From: clownwilleatme Date: Wed, 8 Feb 2017 09:35:58 +1100 Subject: [PATCH 7/9] Adding export to interface definitions Modifying the Context and SaveOptions interfaces so that they are defined as `export interface` so that they are exposed externally. --- xrm/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xrm/index.d.ts b/xrm/index.d.ts index bbdd060c9f..0899cb1fd9 100644 --- a/xrm/index.d.ts +++ b/xrm/index.d.ts @@ -277,7 +277,7 @@ declare namespace Xrm /** * Interface for the xRM application context. */ - interface Context + export interface Context { /** * The client's context instance. @@ -394,7 +394,7 @@ declare namespace Xrm * * @see {@link https://msdn.microsoft.com/en-us/library/dn481607.aspx#Anchor_2} for details. */ - interface SaveOptions + export interface SaveOptions { /** * Indicates whether to use the Book or Reschedule messages rather than the Create or Update messages. From 465a3e9cb384db21360b290d8ac20fe2d171f804 Mon Sep 17 00:00:00 2001 From: clownwilleatme Date: Wed, 8 Feb 2017 12:21:27 +1100 Subject: [PATCH 8/9] Adding tslint and reformatting Adding tslint.json file and reformatting files to conform to the defined rules. --- xrm/index.d.ts | 388 +++++++++++++++++++------------------------ xrm/tslint.json | 39 +++++ xrm/v6/index.d.ts | 8 +- xrm/v6/xrm-tests.ts | 19 +-- xrm/v7/index.d.ts | 24 +-- xrm/v7/parature.d.ts | 2 - xrm/v7/xrm-tests.ts | 30 ++-- xrm/xrm-tests.ts | 40 ++--- 8 files changed, 264 insertions(+), 286 deletions(-) create mode 100644 xrm/tslint.json diff --git a/xrm/index.d.ts b/xrm/index.d.ts index 0899cb1fd9..bd70a6098d 100644 --- a/xrm/index.d.ts +++ b/xrm/index.d.ts @@ -136,7 +136,7 @@ declare namespace Xrm * @return An array of control. */ getControl( delegateFunction: Collection.MatchingDelegate ): Page.Control[]; - } + }; /** * Provides a container for useful functions not directly related to the current page. @@ -214,18 +214,18 @@ declare namespace Xrm * formid */ openWebResource( webResourceName: string, webResourceData?: string, width?: number, height?: number ): Window; - } + }; /** - * Provides methods to create and manage records in the mobile clients (for phones tablets). - */ + * Provides methods to create and manage records in the mobile clients (for phones tablets). + */ Mobile: Mobile; /** - * Provides methods to display a web page in the side pane of web client. - * - * @see {@link https://msdn.microsoft.com/en-us/library/mt790281.aspx} for details. - */ + * Provides methods to display a web page in the side pane of web client. + * + * @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. @@ -235,8 +235,8 @@ declare namespace Xrm * * @remarks This method is only supported for the web client. */ - LoadPanel( url: string, title: string ): void; - } + LoadPanel(url: string, title: string): void; + }; } /** @@ -397,10 +397,10 @@ declare namespace Xrm export interface SaveOptions { /** - * Indicates whether to use the Book or Reschedule messages rather than the Create or Update messages. - * Applicable to appointment, recurring appointment, or service activity records. - */ - UseSchedulingEngine?: boolean; + * Indicates whether to use the Book or Reschedule messages rather than the Create or Update messages. + * Applicable to appointment, recurring appointment, or service activity records. + */ + UseSchedulingEngine?: boolean; } /** @@ -425,12 +425,12 @@ declare namespace Xrm save(): Async.XrmPromise; /** - * Asynchronously saves the record with the option to set callback functions to be executed after the save operation is completed. - * - * @param {saveOptions} saveOptions Options to control how appointment, recurring appointment, or service activity records are processed. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - */ + * Asynchronously saves the record with the option to set callback functions to be executed after the save operation is completed. + * + * @param {saveOptions} saveOptions Options to control how appointment, recurring appointment, or service activity records are processed. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + */ save( saveOptions: SaveOptions ): Async.XrmPromise; /** @@ -452,19 +452,18 @@ declare namespace Xrm export interface Ui { /** - * Displays a form level notification. Any number of notifications can be displayed and will remain until removed using clearFormNotification. - * The height of the notification area is limited so each new message will be added to the top. - * - * @param {string} message The text of the notification message. - * @param {Page.ui.FormNotificationLevel} level The level of the notification which defines how the message will be displayed, such as the icon. - * @param {string} uniqueId Unique identifier for the notification which is used with clearFormNotification to remove the notification. - * - * @return true if it succeeds, otherwise false. - * - * @remarks Values for level are: ERROR Notification will use the system error icon. - * WARNING Notification will use the system warning icon. - * INFO Notification will use the system info icon. - */ + * Displays a form level notification. Any number of notifications can be displayed and will remain until removed using clearFormNotification. + * The height of the notification area is limited so each new message will be added to the top. + * + * @param {string} message The text of the notification message. + * @param {Page.ui.FormNotificationLevel} level The level of the notification which defines how the message will be displayed, such as the icon. + * @param {string} uniqueId Unique identifier for the notification which is used with clearFormNotification to remove the notification. + * + * @return true if it succeeds, otherwise false. + * + * @remarks Values for level are: ERROR Notification will use the system error icon. * WARNING Notification will use the system warning icon. + * INFO Notification will use the system info icon. + */ setFormNotification( message: string, level: Page.ui.FormNotificationLevel, uniqueId: string ): boolean; /** @@ -522,8 +521,8 @@ declare namespace Xrm refreshRibbon(): void; /** - * The business process flow API, used to interact with the business process flow control in a form. - */ + * The business process flow API, used to interact with the business process flow control in a form. + */ process: Page.ui.ProcessManager; /** @@ -551,8 +550,8 @@ declare namespace Xrm tabs: Collection.ItemCollection; /** - * A collection of all the quick view controls on a form using the new form rendering engine (also called "turbo forms"). - */ + * A collection of all the quick view controls on a form using the new form rendering engine (also called "turbo forms"). + */ quickForms: Collection.ItemCollection; } @@ -562,10 +561,10 @@ declare namespace Xrm export interface Mobile { /** - * Provides methods to create and manage records in the mobile clients while working in the offline mode. - * - * @see {@link https://msdn.microsoft.com/en-us/library/mt787123.aspx} for details. - */ + * Provides methods to create and manage records in the mobile clients while working in the offline mode. + * + * @see {@link https://msdn.microsoft.com/en-us/library/mt787123.aspx} for details. + */ offline: MobileOffline; } @@ -577,150 +576,98 @@ declare namespace Xrm export interface MobileOffline { /** - * Returns whether an entity is offline enabled. - * - * @param {string} entityType The logical name of the entity. - * - * @return {boolean} True if the entity is offline enabled; otherwise False. - */ + * Returns whether an entity is offline enabled. + * + * @param {string} entityType The logical name of the entity. + * + * @return {boolean} True if the entity is offline enabled; otherwise False. + */ isOfflineEnabled( entityType: string ): boolean; /** - * Creates an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {Object} data A dictionary object containing key : value pairs for the record to create. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks You cannot create intersect and activity party entities. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ + * Creates an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {Object} data A dictionary object containing key : value pairs for the record to create. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot create intersect and activity party entities. + * Only the following attribute types are supported in offline mode: + * BigInt, Boolean, Customer, DateTime, Decimal, Double, EntityName + * Integer, Lookup, Memo, Money, Owner, Picklist, String, State + * Status, UniqueIdentifier + */ createRecord( entityType: string, data: { [attributeName: string]: any } ): Async.XrmPromise; /** - * Retrieves an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} id GUID of the record to retrieve. - * @param {string} options (Optional) OData system query options to retrieve your data. Supports $select and $expand - * Example: ?$select=name&$expand=primarycontactid($select=contactid,fullname) - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks Only $select option can be specified within $expand. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ + * Retrieves an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to retrieve. + * @param {string} options (Optional) OData system query options to retrieve your data. Supports $select and $expand + * Example: ?$select=name&$expand=primarycontactid($select=contactid,fullname) + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks Only $select option can be specified within $expand. + * Only the following attribute types are supported in offline mode: + * BigInt, Boolean, Customer, DateTime, Decimal, Double, EntityName + * Integer, Lookup, Memo, Money, Owner, Picklist, String, State + * Status, UniqueIdentifier + */ retrieveRecord( entityType: string, id: string, options: string ): Async.XrmPromise; /** - * Retrieves a collection of entity records in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} options (Optional) The logical name of the enti - * @param {string} maxPageSize (Optional) A positive number to indicates the number of entity records to be returned per page. - * If you do not specify this parameter, the default value is passed as 5000. - * If the number of records being retrieved is more than maxPageSize, an @odata.nextLink property - * will be returned, and you can use the value of the @odata.nextLink property with a new GET - * request to return next set of records. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks A maximum of 5000 related records can be retrieved when using $expand. - * Only $select option can be specified within $expand. - * $skip query option is not supported. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ + * Retrieves a collection of entity records in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} options (Optional) The logical name of the enti + * @param {string} maxPageSize (Optional) A positive number to indicates the number of entity records to be returned per page. + * If you do not specify this parameter, the default value is passed as 5000. + * If the number of records being retrieved is more than maxPageSize, an @odata.nextLink property + * will be returned, and you can use the value of the @odata.nextLink property with a new GET + * request to return next set of records. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks A maximum of 5000 related records can be retrieved when using $expand. + * Only $select option can be specified within $expand. + * $skip query option is not supported. + * Only the following attribute types are supported in offline mode: + * BigInt, Boolean, Customer, DateTime, Decimal, Double, EntityName + * Integer, Lookup, Memo, Money, Owner, Picklist, String, State + * Status, UniqueIdentifier + */ retrieveMultipleRecords( entityType: string, options: string, maxPageSize: number ): Async.XrmPromise; /** - * Updates an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} id GUID of the record to update. - * @param {Object} data A dictionary object containing key : value pairs for the record to update. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks You cannot update intersect and activity party entities. - * Only the following attribute types are supported in offline mode: BigInt - * Boolean - * Customer - * DateTime - * Decimal - * Double - * EntityName - * Integer - * Lookup - * Memo - * Money - * Owner - * Picklist - * String - * State - * Status - * UniqueIdentifier - */ + * Updates an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to update. + * @param {Object} data A dictionary object containing key : value pairs for the record to update. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot update intersect and activity party entities. + * Only the following attribute types are supported in offline mode: + * BigInt, Boolean, Customer, DateTime, Decimal, Double, EntityName + * Integer, Lookup, Memo, Money, Owner, Picklist, String, State + * Status, UniqueIdentifier + */ updateRecord( entityType: string, id: string, data: { [attributeName: string]: any } ): Async.XrmPromise; /** - * Deletes an entity record in mobile clients while working in the offline mode. - * - * @param {string} entityType The logical name of the entity. - * @param {string} id GUID of the record to delete. - * - * @return {Async.XrmPromise} Returns an asynchronous promise. - * - * @remarks You cannot delete intersect and activity party entities. - */ + * Deletes an entity record in mobile clients while working in the offline mode. + * + * @param {string} entityType The logical name of the entity. + * @param {string} id GUID of the record to delete. + * + * @return {Async.XrmPromise} Returns an asynchronous promise. + * + * @remarks You cannot delete intersect and activity party entities. + */ deleteRecord( entityType: string, id: string ): Async.XrmPromise; } @@ -777,20 +724,19 @@ declare namespace Xrm */ export type OfflineErrorCallbackDelegate = (error: OfflineErrorCallbackObject) => void; - /** * Object passed to ErrorCallbackDelegate. */ export interface ErrorCallbackObject { /** - * The error code. - */ + * The error code. + */ errorCode: number; /** - * An error message describing the issue. - */ + * An error message describing the issue. + */ message: string; } @@ -800,8 +746,8 @@ declare namespace Xrm export interface OpenQuickCreateSuccessCallbackObject { /** - * A lookup value which identifies the record which has been created. - */ + * A lookup value which identifies the record which has been created. + */ savedEntityReference: Page.LookupValue; } @@ -811,12 +757,13 @@ declare namespace Xrm export interface OfflineOperationSuccessCallbackObject { /** - * GUID of the record; - */ + * GUID of the record; + */ id: string; + /** - * Logical name of the entity. - */ + * Logical name of the entity. + */ logicalName: string; } @@ -826,8 +773,8 @@ declare namespace Xrm export interface OfflineErrorCallbackObject extends ErrorCallbackObject { /** - * An internal error message that might contain additional details about the issue. - */ + * An internal error message that might contain additional details about the issue. + */ debugMessage: string; } @@ -889,10 +836,10 @@ declare namespace Xrm } /** - * Interface for an item collection. - * - * @tparam T Generic type parameter. - */ + * Interface for an item collection. + * + * @tparam T Generic type parameter. + */ export interface ItemCollection { /** @@ -973,11 +920,16 @@ declare namespace Xrm * Submit Mode for Xrm.Page.Attribute.getSubmitMode() and Xrm.Page.Attribute.setSubmitMode(). */ export type SubmitMode = "always" | "dirty" | "never"; + + /** + * Control type for Xrm.Page.ui.QuickForm.getControlType(). + */ + export type ControlQuickFormType = "quickform"; /** * Control types for Xrm.Page.Control.getControlType(). */ - export type ControlType = "standard" | "iframe" | "lookup" | "optionset" | "subgrid" | "webresource" | "notes" | "timercontrol" | "kbsearch" | "quickform"; + export type ControlType = "standard" | "iframe" | "lookup" | "optionset" | "subgrid" | "webresource" | "notes" | "timercontrol" | "kbsearch" | ControlQuickFormType; /** * Date attribute formats for Xrm.Page.Attribute.getFormat(), used by DateAttribute. @@ -1015,12 +967,12 @@ declare namespace Xrm export interface Process { /** - * Returns the unique identifier of the process. - * - * @return The identifier for this process, in GUID format. - * - * @remarks Example: "{825CB223-A651-DF11-AA8B-00155DBA3804}". - */ + * Returns the unique identifier of the process. + * + * @return The identifier for this process, in GUID format. + * + * @remarks Example: "{825CB223-A651-DF11-AA8B-00155DBA3804}". + */ getId(): string; /** @@ -1256,9 +1208,9 @@ declare namespace Xrm } /** - * Interface for controls which methods provide immediate feedback or take actions as user types in a control. - * Contains methods which can be used to perform data validations in a control even before the user commits (saves) the value in a form. - */ + * Interface for controls which methods provide immediate feedback or take actions as user types in a control. + * Contains methods which can be used to perform data validations in a control even before the user commits (saves) the value in a form. + */ export interface UiKeyPressable { /** @@ -2253,7 +2205,7 @@ declare namespace Xrm */ getAttribute(): Attribute; } - + /** * Interface for Auto Lookup Control. * This is not an Entity Lookup, but a control that supports AutoComplete / KeyPress Events (Text or Number) @@ -2852,10 +2804,10 @@ declare namespace Xrm } /** - * Interface for a quick view control instance on a form. - * - * @see {@link https://msdn.microsoft.com/en-us/library/mt736908.aspx#bkmk_isLoaded} for details. - */ + * Interface for a quick view control instance on a form. + * + * @see {@link https://msdn.microsoft.com/en-us/library/mt736908.aspx#bkmk_isLoaded} for details. + */ export interface QuickForm extends Control, UiLabelElement, UiCanGetVisibleElement { /** @@ -2914,27 +2866,27 @@ declare namespace Xrm getControl( index: number ): Page.Control; /** - * Gets the controls type. - * - * @return Returns a string value that categorizes quick view controls. - */ - getControlType(): "quickform"; + * Gets the controls type. + * + * @return Returns a string value that categorizes quick view controls. + */ + getControlType(): ControlQuickFormType; /** - * Returns whether the data binding for the constituent controls in a quick view control is complete. - * - * @return True is the data binding for a constituent control is complete, otherwise false. - * because the quick view form that the control is bound to may not have loaded completely. - * As a result, using the getAttribute or any data-related methods on a constituent control might not work. - * The isLoaded method for the quick view control helps determine the data binding status for constituent controls in a quick view control. - * - * @remarks The data binding for the constituent controls in a quick view control may not be complete during the main form OnLoad event - */ + * Returns whether the data binding for the constituent controls in a quick view control is complete. + * + * @return True is the data binding for a constituent control is complete, otherwise false. + * because the quick view form that the control is bound to may not have loaded completely. + * As a result, using the getAttribute or any data-related methods on a constituent control might not work. + * The isLoaded method for the quick view control helps determine the data binding status for constituent controls in a quick view control. + * + * @remarks The data binding for the constituent controls in a quick view control may not be complete during the main form OnLoad event + */ isLoaded(): boolean; /** - * Refreshes the data displayed in a quick view control. - */ + * Refreshes the data displayed in a quick view control. + */ refresh(): void; } } diff --git a/xrm/tslint.json b/xrm/tslint.json new file mode 100644 index 0000000000..359d3ddb9e --- /dev/null +++ b/xrm/tslint.json @@ -0,0 +1,39 @@ +{ + "rules": { + "class-name": true, + "comment-format": [ true, "check-space" ], + "indent": [ true, "spaces" ], + "no-duplicate-variable": true, + "no-eval": true, + "no-internal-module": false, + "no-trailing-whitespace": false, + "no-var-keyword": true, + "one-line": [ true, "check-whitespace" ], + "quotemark": [ true, "double" ], + "semicolon": true, + "triple-equals": [ true, "allow-null-check" ], + "align": [ true, "parameters", "statements" ], + "jsdoc-format": true, + "no-consecutive-blank-lines": true, + "space-before-function-paren": [ true, "always" ], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "variable-name": [ true, "ban-keywords" ], + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type" + ] + } +} \ No newline at end of file diff --git a/xrm/v6/index.d.ts b/xrm/v6/index.d.ts index 5c624c5f53..fa7ab43463 100644 --- a/xrm/v6/index.d.ts +++ b/xrm/v6/index.d.ts @@ -210,10 +210,10 @@ declare namespace Xrm } /** - * Interface for an item collection. - * - * @tparam T Generic type parameter. - */ + * Interface for an item collection. + * + * @tparam T Generic type parameter. + */ export interface ItemCollection { /** diff --git a/xrm/v6/xrm-tests.ts b/xrm/v6/xrm-tests.ts index 3b911da94d..45d7cbb567 100644 --- a/xrm/v6/xrm-tests.ts +++ b/xrm/v6/xrm-tests.ts @@ -1,13 +1,12 @@ - function _getContext() { - var errorMessage = "Context is not available."; - if ( typeof GetGlobalContext != "undefined" ) + const errorMessage = "Context is not available."; + if ( typeof GetGlobalContext !== "undefined" ) { return GetGlobalContext(); } else { - if ( typeof Xrm != "undefined" ) + if ( typeof Xrm !== "undefined" ) { return Xrm.Page.context; } @@ -15,21 +14,21 @@ function _getContext() } } -var crmContext = _getContext(); +const crmContext = _getContext(); -var grids = Xrm.Page.getControl(( control ) => +const grids = Xrm.Page.getControl(( control ) => { return control.getControlType() === "subgrid"; }); -var selectedGridReferences: Xrm.Page.LookupValue[] = []; +const selectedGridReferences: Xrm.Page.LookupValue[] = []; grids.forEach(( gridControl: Xrm.Page.GridControl ) => { gridControl.refresh(); }); -var lookupAttribute = Xrm.Page.getControl( "customerid" ); +const lookupAttribute = Xrm.Page.getControl( "customerid" ); lookupAttribute.addCustomFilter( ` @@ -37,7 +36,7 @@ lookupAttribute.addCustomFilter( ` lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); }); -var lookupValues = lookupAttribute.getAttribute().getValue(); +const lookupValues = lookupAttribute.getAttribute().getValue(); if ( lookupValues !== null ) if ( !lookupValues[0].id || !lookupValues[0].entityType ) @@ -57,7 +56,7 @@ Xrm.Page.ui.tabs.forEach(( tab ) => Xrm.Page.data.entity.addOnSave(( context ) => { - var eventArgs = context.getEventArgs(); + const eventArgs = context.getEventArgs(); if ( eventArgs.getSaveMode() === Xrm.Page.SaveMode.AutoSave || eventArgs.getSaveMode() === Xrm.Page.SaveMode.SaveAndClose ) eventArgs.preventDefault(); diff --git a/xrm/v7/index.d.ts b/xrm/v7/index.d.ts index ee9d45b252..bfe398fd96 100644 --- a/xrm/v7/index.d.ts +++ b/xrm/v7/index.d.ts @@ -125,7 +125,7 @@ declare namespace Xrm * @return An array of control. */ getControl( delegateFunction: Collection.MatchingDelegate ): Page.Control[]; - } + }; /** * Provides a container for useful functions not directly related to the current page. @@ -207,7 +207,7 @@ declare namespace Xrm * formid */ openWebResource( webResourceName: string, webResourceData?: string, width?: number, height?: number ): Window; - } + }; } /** @@ -552,10 +552,10 @@ declare namespace Xrm } /** - * Interface for an item collection. - * - * @tparam T Generic type parameter. - */ + * Interface for an item collection. + * + * @tparam T Generic type parameter. + */ export interface ItemCollection { /** @@ -640,12 +640,12 @@ declare namespace Xrm export interface Process { /** - * Returns the unique identifier of the process. - * - * @return The identifier for this process, in GUID format. - * - * @remarks Example: "{825CB223-A651-DF11-AA8B-00155DBA3804}". - */ + * Returns the unique identifier of the process. + * + * @return The identifier for this process, in GUID format. + * + * @remarks Example: "{825CB223-A651-DF11-AA8B-00155DBA3804}". + */ getId(): string; /** diff --git a/xrm/v7/parature.d.ts b/xrm/v7/parature.d.ts index ed9c07921b..7823460843 100644 --- a/xrm/v7/parature.d.ts +++ b/xrm/v7/parature.d.ts @@ -3,8 +3,6 @@ // Definitions by: David Berry // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - - declare namespace Xrm.Page { /** diff --git a/xrm/v7/xrm-tests.ts b/xrm/v7/xrm-tests.ts index 217414feb4..1b82805648 100644 --- a/xrm/v7/xrm-tests.ts +++ b/xrm/v7/xrm-tests.ts @@ -9,12 +9,12 @@ parent.Xrm.Page.context.getOrgLcid(); function _getContext() { - var errorMessage = "Context is not available."; - if ( typeof GetGlobalContext != "undefined" ) + const errorMessage = "Context is not available."; + if ( typeof GetGlobalContext !== "undefined" ) { return GetGlobalContext(); } else { - if ( typeof Xrm != "undefined" ) + if ( typeof Xrm !== "undefined" ) { return Xrm.Page.context; } @@ -22,16 +22,16 @@ function _getContext() } } -var crmContext = _getContext(); +const crmContext = _getContext(); /// Demonstrate iterator typing -var grids = Xrm.Page.getControl(( control ) => +const grids = Xrm.Page.getControl(( control ) => { return control.getControlType() === "subgrid"; }); -var selectedGridReferences: Xrm.Page.LookupValue[] = []; +const selectedGridReferences: Xrm.Page.LookupValue[] = []; /// Demonstrate iterator typing with v7.1 additions @@ -40,13 +40,13 @@ grids.forEach(( gridControl: Xrm.Page.GridControl ) => gridControl.getGrid().getSelectedRows().forEach(( row ) => { selectedGridReferences.push( row.getData().getEntity().getEntityReference() ); - }) + }); }); /// Demonstrate generic overload vs typecast -var lookupAttribute = Xrm.Page.getControl( "customerid" ); -var lookupAttribute2 = Xrm.Page.getControl( "customerid" ); +const lookupAttribute = Xrm.Page.getControl( "customerid" ); +const lookupAttribute2 = Xrm.Page.getControl( "customerid" ); /// Demonstrate ES6 String literal syntax @@ -58,7 +58,7 @@ lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); }); /// Demonstrate strong-typed attribute association with strong-typed control -var lookupValues = lookupAttribute.getAttribute().getValue(); +const lookupValues = lookupAttribute.getAttribute().getValue(); if ( lookupValues !== null ) if ( !lookupValues[0].id || !lookupValues[0].entityType ) @@ -67,7 +67,7 @@ if ( lookupValues !== null ) /// Demonstrate v7.0 BPF API if (Xrm.Page.data.process != null) - Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ) }); + Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ); }); /// Demonstrate v7.1 Quick Create form @@ -93,7 +93,7 @@ Xrm.Page.ui.tabs.forEach(( tab ) => Xrm.Page.data.entity.addOnSave(( context ) => { - var eventArgs = context.getEventArgs(); + const eventArgs = context.getEventArgs(); if ( eventArgs.getSaveMode() === XrmEnum.SaveMode.AutoSave || eventArgs.getSaveMode() === XrmEnum.SaveMode.SaveAndClose ) eventArgs.preventDefault(); @@ -107,7 +107,7 @@ alert( `The current entity type is: ${Xrm.Page.data.entity.getEntityName() }` ); /// Demonstrate Optionset Value as int in Turbo Forms -var optionSetAttribute = Xrm.Page.getAttribute( "statuscode" ); +const optionSetAttribute = Xrm.Page.getAttribute( "statuscode" ); const optionValue: number = optionSetAttribute.getOptions()[0].value; /// Demonstrate Control.setFocus(); @@ -116,7 +116,7 @@ optionSetAttribute.controls.get(0).setFocus(); /// Demonstrate setFormNotification -var level: Xrm.Page.ui.FormNotificationLevel; +let level: Xrm.Page.ui.FormNotificationLevel; level = "ERROR"; Xrm.Page.ui.setFormNotification("Test", level, "uniqueId"); @@ -132,5 +132,3 @@ attribute.setSubmitMode(submitMode); attribute.setSubmitMode(submitMode); attribute.setRequiredLevel(requirementLevel); attribute.setRequiredLevel(requirementLevelString); - - diff --git a/xrm/xrm-tests.ts b/xrm/xrm-tests.ts index 1242236f36..41f06cbf1e 100644 --- a/xrm/xrm-tests.ts +++ b/xrm/xrm-tests.ts @@ -1,6 +1,4 @@ - - /// Demonstrate usage in the browser's window object window.Xrm.Utility.alertDialog( "message", () => {} ); @@ -10,12 +8,12 @@ parent.Xrm.Page.context.getOrgLcid(); function _getContext() { - var errorMessage = "Context is not available."; - if ( typeof GetGlobalContext != "undefined" ) + const errorMessage = "Context is not available."; + if ( typeof GetGlobalContext !== "undefined" ) { return GetGlobalContext(); } else { - if ( typeof Xrm != "undefined" ) + if ( typeof Xrm !== "undefined" ) { return Xrm.Page.context; } @@ -23,16 +21,16 @@ function _getContext() } } -var crmContext = _getContext(); +const crmContext = _getContext(); /// Demonstrate iterator typing -var grids = Xrm.Page.getControl(( control ) => +const grids = Xrm.Page.getControl(( control ) => { return control.getControlType() === "subgrid"; }); -var selectedGridReferences: Xrm.Page.LookupValue[] = []; +const selectedGridReferences: Xrm.Page.LookupValue[] = []; /// Demonstrate iterator typing with v7.1 additions @@ -45,8 +43,8 @@ grids.forEach(( gridControl: Xrm.Page.GridControl ) => /// Demonstrate generic overload vs typecast -var lookupAttribute = Xrm.Page.getControl( "customerid" ); -var lookupAttribute2 = Xrm.Page.getControl( "customerid" ); +const lookupAttribute = Xrm.Page.getControl( "customerid" ); +const lookupAttribute2 = Xrm.Page.getControl( "customerid" ); /// Demonstrate ES6 String literal syntax @@ -58,7 +56,7 @@ lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); }); /// Demonstrate strong-typed attribute association with strong-typed control -var lookupValues = lookupAttribute.getAttribute().getValue(); +const lookupValues = lookupAttribute.getAttribute().getValue(); if ( lookupValues !== null ) if ( !lookupValues[0].id || !lookupValues[0].entityType ) @@ -67,11 +65,11 @@ if ( lookupValues !== null ) /// Demonstrate v7.0 BPF API if (Xrm.Page.data.process != null) - Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ) }); + Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ); }); /// Demonstrate v7.1 Quick Create form -Xrm.Utility.openQuickCreate("account").then(( object ) => { if (object) alert( `Newly created record Id: ${object.savedEntityReference.id}` ); }, (error) => {console.log(`Code: ${error.errorCode}, Message: ${error.message}`)}); +Xrm.Utility.openQuickCreate("account").then(( object ) => { if (object) alert( `Newly created record Id: ${object.savedEntityReference.id}` ); }, (error) => {console.log(`Code: ${error.errorCode}, Message: ${error.message}`); }); /// Make all controls visible. @@ -94,7 +92,7 @@ Xrm.Page.ui.tabs.forEach(( tab ) => Xrm.Page.data.entity.addOnSave(( context ) => { - var eventArgs = context.getEventArgs(); + const eventArgs = context.getEventArgs(); if ( eventArgs.getSaveMode() === XrmEnum.SaveMode.AutoSave || eventArgs.getSaveMode() === XrmEnum.SaveMode.SaveAndClose ) eventArgs.preventDefault(); @@ -108,7 +106,7 @@ alert( `The current entity type is: ${Xrm.Page.data.entity.getEntityName() }` ); /// Demonstrate Optionset Value as int in Turbo Forms -var optionSetAttribute = Xrm.Page.getAttribute( "statuscode" ); +const optionSetAttribute = Xrm.Page.getAttribute( "statuscode" ); const optionValue: number = optionSetAttribute.getOptions()[0].value; /// Demonstrate Control.setFocus(); @@ -117,7 +115,7 @@ optionSetAttribute.controls.get(0).setFocus(); /// Demonstrate setFormNotification -var level: Xrm.Page.ui.FormNotificationLevel; +let level: Xrm.Page.ui.FormNotificationLevel; level = "ERROR"; Xrm.Page.ui.setFormNotification("Test", level, "uniqueId"); @@ -137,7 +135,7 @@ attribute.setRequiredLevel(requirementLevelString); // Works if the string is a /// Demonstrate v8 AutoComplete let autoCompleteControl = Xrm.Page.getControl("name"); -var userInput = autoCompleteControl.getValue(); +const userInput = autoCompleteControl.getValue(); const accountResult = { }; const resultSet: Xrm.Page.AutoCompleteResultSet = { results: new Array() as Xrm.Page.AutoCompleteResult[], @@ -165,8 +163,6 @@ autoCompleteControl.removeOnKeyPress(() => {}); autoCompleteControl.showAutoComplete(resultSet); autoCompleteControl.hideAutoComplete(); - - /// Demonstrate v8.2 quick form controls const quickForm = Xrm.Page.ui.quickForms.get(0); @@ -180,14 +176,10 @@ quickForm.refresh(); // Get standard control const ctrl = Xrm.Page.getControl("controlName"); -ctrl.getControlType() +ctrl.getControlType(); ctrl.getName(); ctrl.getParent(); ctrl.getLabel(); ctrl.setLabel("Label name"); ctrl.getVisible(); ctrl.setVisible(true); - - - - From 8a9e8cac53a7f6432e985519ad6a49043aa75b42 Mon Sep 17 00:00:00 2001 From: clownwilleatme Date: Wed, 8 Feb 2017 12:27:58 +1100 Subject: [PATCH 9/9] Removing tslint rule Removing the tslint space-before-function-paren rule as it caused hundreds of errors with Travis CI. --- xrm/tslint.json | 1 - 1 file changed, 1 deletion(-) diff --git a/xrm/tslint.json b/xrm/tslint.json index 359d3ddb9e..0e45822b24 100644 --- a/xrm/tslint.json +++ b/xrm/tslint.json @@ -15,7 +15,6 @@ "align": [ true, "parameters", "statements" ], "jsdoc-format": true, "no-consecutive-blank-lines": true, - "space-before-function-paren": [ true, "always" ], "typedef-whitespace": [ true, {