Skip to content

Commit 2f08913

Browse files
authored
Update override-default-open-behavior-grids.md
Add a new updated approach to modify the default open behavior with the new Power Apps Grid Control
1 parent c08523a commit 2f08913

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

powerapps-docs/developer/model-driven-apps/override-default-open-behavior-grids.md

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,67 @@ By default, performing any of the following actions in a data row in an entity-b
2626

2727
[!INCLUDE[cc-terminology](../data-platform/includes/cc-terminology.md)]
2828

29-
There might be situations where you don't want the table record to open (which is the default behavior), but want a custom action to be performed such as opening a URL using JavaScript functions. You can override the default behavior and define your own custom behavior by creating a command definition for a table with `Mscrm.OpenRecordItem` as the value of the ID parameter `CommandDefinition`, and defining a custom action on the **Actions** tab. The application looks for the `Mscrm.OpenRecordItem` command ID for a table when you try to open a record from the entity-bound grid and—if one is present—will execute the custom action instead of performing the default behavior of opening the table record.
29+
There might be situations where you don't want the table record to open (which is the default behavior), but want a custom action to be performed such as opening a URL using JavaScript functions.
30+
<br /><br />
31+
There are two approaches to acheive this:
32+
33+
## Approach 1 - Using the Power Apps Editable Grid
34+
35+
### Step 1: Create a web resource
36+
37+
Create a web resource to change the default behavior. In the following example, if you want to open a URL instead of displaying the record, you create a JavaScript web resource to perform that action.
38+
39+
1. Sign in to [Power Apps](https://make.powerapps.com) and select **Solutions** from the left pane.
40+
41+
2. Select **New solution**, and then complete the required columns for the solution.
42+
43+
|Column|Description|
44+
|-----------|-----------------|
45+
|**Display Name**|The name shown in the list of solutions. You can change this later.|
46+
|**Name**|The unique name of the solution. This is generated by using the value you enter in the **Display Name** column. You can edit this before you save the solution, but after you save the solution, you can't change it.|
47+
|**Publisher**|You can select the default publisher or create a new publisher. We recommend that you create a publisher for your organization to use consistently across the environments where you'll use the solution.|
48+
|**Version**|Enter a number for the version of your solution. This is only important if you export your solution. The version number will be included in the file name when you export the solution.|
49+
50+
3. Select **Save**.
51+
52+
4. Open the solution, and then select **New** > **Other** > **Web resource**.
53+
54+
> [!div class="mx-imgBorder"]
55+
> ![Create a web resource.](media/create-new-web-resources.png "Create a web resource")
56+
57+
5. Enter the name of the web resource, and select the **Type** as **JavaScript (JS)**.
58+
59+
6. Select **Text Editor**, copy the code shown below, paste it into the text editor, and enter the value of the URL you want to open:
60+
61+
```JavaScript
62+
function ChangeBehavior(){
63+
64+
// Enter the url
65+
var url = "Enter the URL";
66+
var OpenUrlOptions = {height: 800, width: 1000};
67+
Xrm.Navigation.openUrl(url, openUrlOptions);
68+
}
69+
```
70+
7. Save and publish the web resource.
71+
72+
### Step 2: Enable Power Apps Grid Control
73+
Follow these steps to enable the **Power Apps Grid Control** as the main grid (table view) or within a model-driven form subgrid:
74+
- (Use as main grid)[power-apps/maker/model-driven-apps/the-power-apps-grid-control#add-the-power-apps-grid-control-to-views-for-an-entity]
75+
- (Use as subgrid)[power-apps/maker/model-driven-apps/the-power-apps-grid-control#add-the-power-apps-grid-control-to-a-subgrid]
76+
77+
78+
### Step 3: Register the custom behavior on OnRecordSelect Event
79+
The Power Apps Grid Control has a [OnRecordSelect](/power-apps/developer/model-driven-apps/clientapi/reference/events/grid-onrecordselect) event which we will use to register the JavaScript function created from Step 1. When enabling the **Power Apps Grid Control** from Step 2, an **Events** tab appears. Select the **Events** tab:
80+
1. Under the **Form Libraries** section, add the Form Libary from the web resource created in Step 1
81+
2. Under the **Event Handlers** section, select the event **OnRecordSelect** and click Add, a popup will appear
82+
3. In the popup, select the form library just added and the Function name **ChangeBehavior**. This is the name of the function in the web resource.
83+
84+
85+
For more infomation, see (Power Apps Grid Control)[power-apps/maker/model-driven-apps/the-power-apps-grid-control]
86+
87+
88+
## Approach 2 - Creating a Command Definition
89+
You can override the default behavior and define your own custom behavior by creating a command definition for a table with `Mscrm.OpenRecordItem` as the value of the ID parameter `CommandDefinition`, and defining a custom action on the **Actions** tab. The application looks for the `Mscrm.OpenRecordItem` command ID for a table when you try to open a record from the entity-bound grid and&mdash;if one is present&mdash;will execute the custom action instead of performing the default behavior of opening the table record.
3090

3191
> [!NOTE]
3292
> - This feature is supported only for Unified Interface.
@@ -38,7 +98,7 @@ To specify a custom action when a table record is selected, you'll do the follow
3898
2. Create a custom button on the form by editing the customization.xml file
3999
3. Import the customization.xml file
40100

41-
## Step 1: Create a web resource
101+
### Step 1: Create a web resource
42102

43103
Create a web resource to change the default behavior. In the following example, if you want to open a URL instead of displaying the record, you create a JavaScript web resource to perform that action.
44104

@@ -75,7 +135,7 @@ Create a web resource to change the default behavior. In the following example,
75135
```
76136
7. Save and publish the web resource.
77137

78-
## Step 2: Create a custom button
138+
### Step 2: Create a custom button
79139

80140
Create a custom button on the form where you want to change the default behavior. For example, if you have a subgrid on the accounts form that displays contact records in the subgrid, you need to create a button and add it to the contact form. You can create a button by editing the customization.xml file.
81141

@@ -154,7 +214,7 @@ Create a custom button on the form where you want to change the default behavior
154214
>
155215
> This example is to change the button for a button for a subgrid on the accounts form that displays contact records in the subgrid. Therefore the `Location` is `Location="Mscrm.SubGrid.contact.MainTab.Management.Controls._children"`. You will need to change this to have this apply to a different button.
156216

157-
## Step 3: Import the XML file
217+
### Step 3: Import the XML file
158218

159219
1. After you've edited the customization.xml file, right-click to select the **customization.xml** tab, and then select **Open Containing Folder**.
160220
2. Select all the files or folders that were included when you extracted the solution. Right-click the selected files, select **Send To**, and then select **Compressed (zipped) folder**.

0 commit comments

Comments
 (0)