Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions types/xrm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2753,6 +2753,11 @@ declare namespace Xrm {
* @see {@link Attribute}
*/
interface NumberAttribute extends Attribute<number> {
/**
* Get the attribute type.
* @returns The attribute type.
*/
getAttributeType(): "integer" | "decimal" | "double" | "money";
/**
* Gets the attribute format.
* @returns The format of the attribute.
Expand Down Expand Up @@ -2797,6 +2802,11 @@ declare namespace Xrm {
* @see {@link Attribute}
*/
interface StringAttribute extends Attribute<string> {
/**
* Get the attribute type.
* @returns The attribute type.
*/
getAttributeType(): "string";
/**
* Gets the attribute format.
* @returns The format of the attribute.
Expand Down Expand Up @@ -2846,17 +2856,17 @@ declare namespace Xrm {
* @see {@link EnumAttribute}
*/
interface BooleanAttribute extends EnumAttribute<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<Controls.BooleanControl>;

/**
* 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<Controls.BooleanControl>;
}

/**
Expand All @@ -2865,6 +2875,12 @@ declare namespace Xrm {
* @see {@link Attribute}
*/
interface DateAttribute extends Attribute<Date> {
/**
* Gets the attribute type.
* @returns The attribute type.
*/
getAttributeType(): "datetime";

/**
* Gets the attribute format.
*
Expand All @@ -2885,6 +2901,12 @@ declare namespace Xrm {
* @see {@link EnumAttribute}
*/
interface OptionSetAttribute<T extends number = number> extends EnumAttribute<T> {
/**
* Gets the attribute type.
* @returns The attribute type.
*/
getAttributeType(): "optionset";

/**
* Gets the attribute format.
* @returns The format of the attribute.
Expand Down Expand Up @@ -2946,6 +2968,11 @@ declare namespace Xrm {
* @see {@link EnumAttribute}
*/
interface MultiSelectOptionSetAttribute<T extends number = number> extends EnumAttribute<T[]> {
/**
* Gets the attribute type.
* @returns The attribute type.
*/
getAttributeType(): "multiselectoptionset";
/**
* Gets the attribute format.
* @returns The format of the attribute.
Expand Down Expand Up @@ -3008,6 +3035,11 @@ declare namespace Xrm {
* @see {@link Attribute}
*/
interface LookupAttribute extends Attribute<LookupValue[]> {
/**
* 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.
Expand Down Expand Up @@ -3275,7 +3307,7 @@ declare namespace Xrm {
* * customcontrol: <namespace>.<name> (A custom control for mobile phone and tablet clients).
* * customsubgrid: <namespace>.<name> (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.
Expand Down
15 changes: 13 additions & 2 deletions types/xrm/xrm-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<Xrm.Attributes.StringAttribute>("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
}