diff --git a/types/xrm/index.d.ts b/types/xrm/index.d.ts index e89eee0f61e0d3..f33d6bc8e080cb 100644 --- a/types/xrm/index.d.ts +++ b/types/xrm/index.d.ts @@ -2753,6 +2753,11 @@ declare namespace Xrm { * @see {@link Attribute} */ interface NumberAttribute extends Attribute { + /** + * Get the attribute type. + * @returns The attribute type. + */ + getAttributeType(): "integer" | "decimal" | "double" | "money"; /** * Gets the attribute format. * @returns The format of the attribute. @@ -2797,6 +2802,11 @@ declare namespace Xrm { * @see {@link Attribute} */ interface StringAttribute extends Attribute { + /** + * Get the attribute type. + * @returns The attribute type. + */ + getAttributeType(): "string"; /** * Gets the attribute format. * @returns The format of the attribute. @@ -2846,17 +2856,17 @@ declare namespace Xrm { * @see {@link EnumAttribute} */ interface BooleanAttribute extends EnumAttribute { - /** - * A collection of all the controls on the form that interface with this attribute. - * @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/collections External Link: Collections (Client API reference)} - */ - controls: Collection.ItemCollection; - /** * Gets the attribute format. * @returns the string "boolean" */ getAttributeType(): "boolean"; + + /** + * A collection of all the controls on the form that interface with this attribute. + * @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/collections External Link: Collections (Client API reference)} + */ + controls: Collection.ItemCollection; } /** @@ -2865,6 +2875,12 @@ declare namespace Xrm { * @see {@link Attribute} */ interface DateAttribute extends Attribute { + /** + * Gets the attribute type. + * @returns The attribute type. + */ + getAttributeType(): "datetime"; + /** * Gets the attribute format. * @@ -2885,6 +2901,12 @@ declare namespace Xrm { * @see {@link EnumAttribute} */ interface OptionSetAttribute extends EnumAttribute { + /** + * Gets the attribute type. + * @returns The attribute type. + */ + getAttributeType(): "optionset"; + /** * Gets the attribute format. * @returns The format of the attribute. @@ -2946,6 +2968,11 @@ declare namespace Xrm { * @see {@link EnumAttribute} */ interface MultiSelectOptionSetAttribute extends EnumAttribute { + /** + * Gets the attribute type. + * @returns The attribute type. + */ + getAttributeType(): "multiselectoptionset"; /** * Gets the attribute format. * @returns The format of the attribute. @@ -3008,6 +3035,11 @@ declare namespace Xrm { * @see {@link Attribute} */ interface LookupAttribute extends Attribute { + /** + * Gets the attribute type. + */ + getAttributeType(): "lookup"; + /** * Gets a boolean value indicating whether the Lookup is a multi-value PartyList. * @returns true the attribute is a PartyList, otherwise false. @@ -3275,7 +3307,7 @@ declare namespace Xrm { * * 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(): ControlType | `${string}.${string}`; /** * Gets the name of the control on the form. diff --git a/types/xrm/xrm-tests.ts b/types/xrm/xrm-tests.ts index a04a5648da3ce0..f45e734e20e46b 100644 --- a/types/xrm/xrm-tests.ts +++ b/types/xrm/xrm-tests.ts @@ -224,8 +224,8 @@ if (attribute !== null) { attribute.setSubmitMode(submitModeString); // Works if the string is a const attribute.setRequiredLevel(requirementLevel); attribute.setRequiredLevel(requirementLevelString); // Works if the string is a const - - const isMulitselect = attribute.getAttributeType() === "multiselectoptionset"; + // @ts-expect-error + const isMultiSelectAttribute = attribute.getAttributeType() === "multiselectoptionset"; // This will return false because the attribute is a LookupAttribute } /// Demonstrate v8.2 quick form controls @@ -758,3 +758,14 @@ function GetAll(context: Xrm.FormContext) { throw new Error("Will return an empty array if no controls are present."); } } + +function testAttributeType(formContext: Xrm.FormContext) { + const attribute = formContext.getAttribute("myattribute"); + if (attribute === null) { + return; + } + const attributeType = attribute.getAttributeType(); + // @ts-expect-error + const isNumberAttribute = attributeType === "number"; // This errors because the attribute is a StringAttribute, not a NumberAttribute + const isStringAttribute = attributeType === "string"; // This works because the attribute is a StringAttribute +}