Skip to content

Commit 2bc650e

Browse files
authored
Updates replicated from the CE repo
1 parent b1a0e0a commit 2bc650e

File tree

1 file changed

+59
-24
lines changed

1 file changed

+59
-24
lines changed

powerapps-docs/developer/model-driven-apps/define-ribbon-enable-rules.md

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
title: "Define ribbon enable rules (model-driven apps) | Microsoft Docs" # Intent and product brand in a unique string of 43-59 chars including spaces"
33
description: "Learn about defining specific rules to control when the ribbon elements are enabled during configuration of ribbon elements." # 115-145 characters including spaces. This abstract displays in the search result."
44
keywords: ""
5-
ms.date: 10/31/2018
5+
ms.date: 02/08/2019
66
ms.service:
77
- "powerapps"
88
ms.custom:
99
- ""
1010
ms.topic: article
1111
ms.assetid: 201f5db9-be65-7c3b-8202-822d78338bd6
12-
author: JimDaly # GitHub ID
13-
ms.author: jdaly # MSFT alias of Microsoft employees only
14-
manager: shilpas # MSFT alias of manager or PM counterpart
15-
ms.reviewer:
12+
author: JesseParsons
13+
ms.author: jeparson
14+
manager: annbe
15+
ms.reviewer: kvivek
1616
search.audienceType:
1717
- developer
1818
search.app:
@@ -22,8 +22,6 @@ search.app:
2222

2323
# Define ribbon enable rules
2424

25-
<!-- https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/customize-dev/define-ribbon-enable-rules -->
26-
2725
When configuring Ribbon elements you can define specific rules to control when the ribbon elements are enabled. The `<EnableRule>` element is used as follows:
2826

2927
- Use the `/RuleDefinitions/EnableRules/EnableRule` element to define rules controlling when the ribbon element should be enabled.
@@ -48,9 +46,9 @@ When configuring Ribbon elements you can define specific rules to control when t
4846

4947
| Value | Presentation |
5048
|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
51-
| `Modern` | The command bar is presented using Dynamics 365 for tablets. |
49+
| `Modern` | The command bar is presented using [!INCLUDE[pn_moca_full](../../includes/pn-moca-full.md)]. |
5250
| `Refresh` | The command bar is presented using the updated user interface. |
53-
| `Legacy` | The ribbon is presented in forms for entities that were not updated or in a list view in Dynamics 365 for Outlook. |
51+
| `Legacy` | The ribbon is presented in forms for entities that were not updated or in a list view in [!INCLUDE[pn_crm_for_outlook_full](../../includes/pn-crm-for-outlook-full.md)]. |
5452

5553
### Crm Client Type Rule
5654
Uses the `<CrmClientTypeRule>` element to allow definition of rules depending on the type of client used. Type options are as follows:
@@ -60,27 +58,64 @@ Uses the `<CrmClientTypeRule>` element to allow definition of rules depending o
6058
- `Outlook`
6159

6260
### Crm Offline Access State Rule
63-
Uses the `<CrmOfflineAccessStateRule>` element. Use this criteria to enable a ribbon element based on whether Dynamics 365 for Microsoft Office Outlook with Offline Access is currently offline.
61+
Uses the `<CrmOfflineAccessStateRule>` element. Use this criteria to enable a ribbon element based on whether [!INCLUDE[pn_crm_outlook_offline_access](../../includes/pn-crm-outlook-offline-access.md)] is currently offline.
6462

6563
### Crm Outlook Client Type Rule
66-
Uses the `<CrmOutlookClientTypeRule>` element. Use this rule if you want to only display a button for a specific type of Dynamics 365 for Outlook. Type options are as follows:
64+
Uses the `<CrmOutlookClientTypeRule>` element. Use this rule if you want to only display a button for a specific type of [!INCLUDE[pn_crm_for_outlook_full](../../includes/pn-crm-for-outlook-full.md)]. Type options are as follows:
6765

6866
- `CrmForOutlook`
6967

7068
- `CrmForOutlookOfflineAccess`
7169

7270
### Custom Rule
73-
Uses the `<CustomRule>` element. Use this kind of rule to call a function in a JavaScript Library that returns a Boolean value.
71+
Uses the `<CustomRule>` element. Use this kind of rule to call a function in a JavaScript library that returns a Promise (Unified Interface) or boolean (Unified Interface and web client).
72+
73+
```JavaScript
74+
function EnableRule()
75+
{
76+
const value = Xrm.Page.getAttribute("field1").getValue();
77+
return value === "Active";
78+
}
79+
```
7480

7581
> [!NOTE]
76-
> Custom rules that do not return a value quickly can affect the performance of the ribbon. If you have to perform logic that might take some time to complete, use the following strategy to make your custom rule asynchronous:
77-
>
78-
> 1. Define a rule that checks for a custom object. You might check for an object such as `Window.ContosoCustomObject.RuleIsTrue` that you just attach to the Window.
79-
> 2. If that object exists, return it.
80-
> 3. If that object does not exist, define the object and set the value as false.
81-
> 4. Before you return a value, use [settimeout](https://msdn.microsoft.com/library/ms536753\(VS.85\).aspx) <!-- TODO not sure about this link--> to execute an asynchronous callback function to re-set the object. Then return false.
82-
> 5. After the callback function has performed the operations that are required to determine the correct result, it sets the value of the object and uses the `refreshRibbon` method to refresh the ribbon.
83-
> 6. When the ribbon is refreshed, it detects the object together with the accurate value set and the rule is evaluated.
82+
> Custom rules that do not return a value quickly can affect the performance of the ribbon. If you have to perform logic that might take some time to complete (for example, a network request), use the following strategy to make your custom rule asynchronous.
83+
84+
Unified Interface rules support returning a Promise rather than boolean for asynchronous rule evaluation. If the promise does not resolve within 10 seconds, the rule will resolve with a false value.
85+
> [!NOTE]
86+
> Promises-based rules will only work on Unified Interface, so they cannot be used if classic Web Client is still being used.
87+
```JavaScript
88+
function EnableRule()
89+
{
90+
const request = new XMLHttpRequest();
91+
request.open('GET', '/bar/foo');
92+
93+
return new Promise((resolve, reject) =>
94+
{
95+
request.onload = function (e)
96+
{
97+
if (request.readyState === 4)
98+
{
99+
if (request.status === 200)
100+
{
101+
resolve(request.responseText === "true");
102+
}
103+
else
104+
{
105+
reject(request.statusText);
106+
}
107+
}
108+
};
109+
request.onerror = function (e)
110+
{
111+
reject(request.statusText);
112+
};
113+
114+
request.send(null);
115+
});
116+
}
117+
```
118+
84119

85120
### Entity Rule
86121
Uses the `<EntityRule>` element. Entity rules allow for evaluation of the current entity. This is useful when you define custom actions that apply to the Entity Template instead of for specific entities. For example, you may want to add a ribbon element to all entities except for several specific entities. It is easier to define the custom action for the Entity Template that applies to all entities and then use an Entity Rule to filter out those that should be excluded.
@@ -104,10 +139,10 @@ Uses the `<CrmClientTypeRule>` element to allow definition of rules depending o
104139
Uses the `<OrRule>` element. The `OrRule` lets you override the default AND comparison for multiple enable rule types. Use the `OrRule` element to define several possible valid combinations to check.
105140

106141
### Outlook Item Tracking Rule
107-
Uses the `<OutlookItemTrackingRule>` element. Use the `TrackedInCrm` attribute for this element to determine whether the record is being tracked in Common Data Service for Apps.
142+
Uses the `<OutlookItemTrackingRule>` element. Use the `TrackedInCrm` attribute for this element to determine whether the record is being tracked in [!INCLUDE[pn_dynamics_crm](../../includes/pn-dynamics-crm.md)] Customer Engagement.
108143

109144
### Outlook Version Rule
110-
Uses the `<OutlookVersionRule>` element. Use this to enable a ribbon element for a specific version of Office Outlook as follows:
145+
Uses the `<OutlookVersionRule>` element. Use this to enable a ribbon element for a specific version of [!INCLUDE[pn_MS_Outlook_Full](../../includes/pn-ms-outlook-full.md)] as follows:
111146

112147
- `2003`
113148

@@ -125,7 +160,7 @@ Uses the `<CrmClientTypeRule>` element to allow definition of rules depending o
125160
Uses the `<SelectionCountRule>` element. Use this kind of rule with a ribbon displayed for a list to enable a button when specific maximum and minimum numbers of records in the grid are selected. For example, if your button merges records, you should make sure at least two records are selected before enabling the ribbon control.
126161

127162
### Sku Rule
128-
Uses the `<SkuRule>` element. Use this kind of rule to enable a ribbon element for a specific SKU version of Dynamics 365 as follows:
163+
Uses the `<SkuRule>` element. Use this kind of rule to enable a ribbon element for a specific SKU version of [!INCLUDE[pn_dynamics_crm](../../includes/pn-dynamics-crm.md)] as follows:
129164

130165
- `OnPremise`
131166

@@ -134,7 +169,7 @@ Uses the `<CrmClientTypeRule>` element to allow definition of rules depending o
134169
- `Spla`
135170

136171
### Value Rule
137-
Uses the `<ValueRule>` element. Use this rule to check the value of a specific field in the record being displayed in the form. You must specify the `Field` and the `Value` to check.
172+
Uses the `<ValueRule>` element. Use this rule to check the value of a specific field in the record being displayed in the form. You must specify the `Field` and the `Value` to check.
138173

139174
### See also
140175
[Customize commands and the ribbon](customize-commands-ribbon.md)

0 commit comments

Comments
 (0)