Skip to main content

Function: MnOnEnableRule

MnOnEnableRule(name): (target: any, key: any, descriptor: PropertyDescriptor) => void

Decorator that marks a method as an event handler for enable rule event.

This event is fired when the state of the associated command is checked by Power Apps.

Remarks

Available on pages: Record and list.

Registration: Manual registration only. You can use Ribbon Workbench to register this event or the Command Bar Editor of Power Apps.

For more information, see Microsoft Client API Reference

Example

Enable phone call button when the contact has a phone number.

@MnComponent({
scope: {
pageType: "record",
table: "contact"
})
export class EnablePhoneCallButtonComponent {
@MnOnEnableRule("phoneCallEnableRule")
canCall(eventArg: CommandBarEventArg) {
const formCtx = eventArg.selectedControl as Xrm.FormContext;
return formCtx.getAttribute("telephone1").getValue() != null;
}

// Refresh the command bar when the phone number is changed.
@MnOnColumnChange("telephone1")
onPhoneChange(eventArg: FormEventArg) {
eventArg.formCtx.ui.refreshRibbon();
}
}

Parameters

NameTypeDescription
nameValueOrConfigPropertyMapper<string>Name of the enable rules or callback function that returns the name of the enable rule from the component configuration.

Returns

fn

▸ (target, key, descriptor): void

Parameters
NameType
targetany
keyany
descriptorPropertyDescriptor
Returns

void

Defined in

packages/core/src/core/metadata/events.ts:146