You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: powerapps-docs/developer/model-driven-apps/clientapi/reference/events/grid-onrecordselect.md
+53-2Lines changed: 53 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -3,20 +3,71 @@ title: "Grid OnRecordSelect event (Client API reference) in model-driven apps| M
3
3
description: Includes description and supported parameters for the grid OnRecordSelect event.
4
4
author: jasongre
5
5
ms.author: jasongre
6
-
ms.date: 03/12/2022
6
+
ms.date: 06/28/2023
7
7
ms.reviewer: jdaly
8
8
ms.topic: reference
9
9
applies_to: "Dynamics 365 (online)"
10
10
search.audienceType:
11
11
- developer
12
12
contributors:
13
13
- JimDaly
14
+
- ericregnier
14
15
---
15
16
# Grid OnRecordSelect event (Client API reference)
16
17
17
-
The `OnRecordSelect` event occurs when a single row (record) is selected in the editable grid. This event won't occur if a user selects different cells in the same row, or selects multiple rows.
18
+
The `OnRecordSelect` event occurs when a single row (record) is selected in the editable grid. This event won't occur if a user selects different cells in the same row, or selects multiple rows.
18
19
20
+
## Example: Override the default open behavior in model-driven grids
19
21
22
+
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. Here is an example to achieve this using the [Power Apps grid control](../../../../../maker/model-driven-apps/the-power-apps-grid-control.md) and the `OnRecordSelect` event.
23
+
24
+
### Step 1: Create a web resource
25
+
26
+
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.
27
+
28
+
1. Sign in to [Power Apps](https://make.powerapps.com) and select **Solutions** from the left pane.
29
+
1. Select **New solution**, and then complete the required columns for the solution.
30
+
31
+
|Column|Description|
32
+
|-----------|-----------------|
33
+
|**Display Name**|The name shown in the list of solutions. You can change this later.|
34
+
|**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.|
35
+
|**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.|
36
+
|**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.|
37
+
1. Select **Save**.
38
+
1. Open the solution, and then select **New** > **Other** > **Web resource**.
39
+
1. Enter the name of the web resource, and select the **Type** as **JavaScript (JS)**.
40
+
1. 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:
41
+
42
+
```JavaScript
43
+
functionChangeBehavior(){
44
+
45
+
// Enter the url
46
+
var url ="Enter the URL";
47
+
var OpenUrlOptions = {height:800, width:1000};
48
+
Xrm.Navigation.openUrl(url, openUrlOptions);
49
+
}
50
+
```
51
+
52
+
1. Save and publish the web resource.
53
+
54
+
### Step 2: Enable Power Apps Grid Control
55
+
56
+
Follow these steps to enable the **Power Apps Grid Control** as the main grid (table view) or within a model-driven form subgrid:
57
+
58
+
-[Use as main grid](../../../../../maker/model-driven-apps/the-power-apps-grid-control.md#add-the-power-apps-grid-control-to-views-for-an-entity)
59
+
-[Use as subgrid](../../../../../maker/model-driven-apps/the-power-apps-grid-control.md#add-the-power-apps-grid-control-to-a-subgrid)
60
+
61
+
### Step 3: Register the custom behavior on OnRecordSelect Event
62
+
63
+
When enabling the **Power Apps Grid Control**, an **Events** tab appears. Select the **Events** tab:
64
+
65
+
1. Under the **Form Libraries** section, add the Form Library from the web resource just created.
66
+
1. Under the **Event Handlers** section, select the event **OnRecordSelect** and click **Add**, a popup will appear.
67
+
1. In the popup, select the form library just added and the function name **ChangeBehavior**. This is the name of the JavaScript function created in the web resource.
68
+
69
+
70
+
More information: [Power Apps grid control](../../../../../maker/model-driven-apps/the-power-apps-grid-control.md)
0 commit comments