Skip to content

Commit 73532e6

Browse files
authored
Update grid-onrecordselect.md
Fixed URLs and updated example to use current select entity iD
1 parent 4adec4e commit 73532e6

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

powerapps-docs/developer/model-driven-apps/clientapi/reference/events/grid-onrecordselect.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ contributors:
1717
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.
1818

1919
## Override the default open behavior in model-driven grids
20-
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 acheive this using the [Power Apps Grid Control](/power-apps/maker/model-driven-apps/the-power-apps-grid-control) and the `OnRecordSelect` event.
20+
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 acheive this using the [Power Apps Grid Control](../../../../../maker/model-driven-apps/the-power-apps-grid-control) and the `OnRecordSelect` event.
2121

2222
### Step 1: Create a web resource
2323

@@ -40,32 +40,33 @@ Create a web resource to change the default behavior. In the following example,
4040

4141
5. Enter the name of the web resource, and select the **Type** as **JavaScript (JS)**.
4242

43-
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:
43+
6. Select **Text Editor**, copy the code shown below, paste it into the text editor. This example uses the **contact** table. Set the `entityName` to the table you want.
4444

4545
```JavaScript
46-
function ChangeBehavior(){
47-
48-
// Enter the url
49-
var url = "Enter the URL";
50-
var OpenUrlOptions = {height: 800, width: 1000};
51-
Xrm.Navigation.openUrl(url, openUrlOptions);
52-
}
46+
function OnSelect(context) {
47+
var pageInput = {
48+
pageType: "entityrecord",
49+
entityName: "contact",
50+
entityId: context.getFormContext().data.entity.getId()
51+
};
52+
Xrm.Navigation.navigateTo(pageInput);
53+
}
5354
```
5455
7. Save and publish the web resource.
5556

5657
### Step 2: Enable Power Apps Grid Control
57-
Follow these steps to enable the **Power Apps Grid Control** as the main grid (table view) or within a model-driven form subgrid:
58-
- [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)
59-
- [Use as subgrid](/power-apps/maker/model-driven-apps/the-power-apps-grid-control#add-the-power-apps-grid-control-to-a-subgrid)
58+
Follow these steps to enable the **Power Apps Grid Control** as the main grid (table view) or within a model-driven form subgrid.
59+
- [Use as main grid](../../../../../maker/model-driven-apps/the-power-apps-grid-control#add-the-power-apps-grid-control-to-views-for-an-entity)
60+
- [Use as subgrid](../../../../../maker/model-driven-apps/the-power-apps-grid-control#add-the-power-apps-grid-control-to-a-subgrid)
6061

6162

6263
### Step 3: Register the custom behavior on OnRecordSelect Event
6364
When enabling the **Power Apps Grid Control**, an **Events** tab appears. Select the **Events** tab:
6465
1. Under the **Form Libraries** section, add the Form Libary from the web resource just created.
6566
2. Under the **Event Handlers** section, select the event **OnRecordSelect** and click Add, a popup will appear.
66-
3. 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.
67+
3. In the popup, select the form library just added and the Function name **OnSelect**. This is the name of the JavaScript function created in the web resource, and check the option **Pass execution context as first parameter**.
6768

6869

69-
For more infomation, see [Power Apps Grid Control](../../../../power-apps/maker/model-driven-apps/the-power-apps-grid-control)
70+
For more infomation, see [Power Apps Grid Control](../../../../../maker/model-driven-apps/the-power-apps-grid-control)
7071

7172
[!INCLUDE[footer-include](../../../../../includes/footer-banner.md)]

0 commit comments

Comments
 (0)