Skip to content

Commit 8004f6f

Browse files
authored
Update grid-onrecordselect.md
Added namespace to follow guidelines in the create edit webresource doc and set a formId to the navigateTo give a better example
1 parent b3c32bd commit 8004f6f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ 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
## Example: 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](../../../../../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. In this example it simply navigates to a specific contact form.
2121

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

24-
Create, save and publish a JavaScript (JS) web resource that contains the following code. This example uses **contact** table. Set the `entityName` you want to use.
24+
Create, save and publish a JavaScript (JS) web resource that contains the following code. This example uses **contact** table and a specific form. Set the `entityName` you want to use.
2525

2626
```JavaScript
27-
function OnSelect(context) {
28-
var pageInput = {
29-
pageType: "entityrecord",
30-
entityName: "contact",
31-
entityId: context.getFormContext().data.entity.getId()
32-
};
33-
Xrm.Navigation.navigateTo(pageInput);
34-
}
27+
var Example = window.Example || {};
28+
(function () {
29+
this.OnSelect = function (executionContext) {
30+
var pageInput = {
31+
pageType: "entityrecord",
32+
entityName: "contact",
33+
entityId: executionContext.getFormContext().data.entity.getId(),
34+
formId: "420786E3-D342-4A9A-914B-AA331FF2D25E"
35+
};
36+
Xrm.Navigation.navigateTo(pageInput);
37+
}
38+
}).call(Example);
3539
```
3640

3741
More information: [Create or edit model-driven app web resources ](../../../../../maker/model-driven-apps/create-edit-web-resources.md)
@@ -46,7 +50,7 @@ Follow these steps to enable the **Power Apps Grid Control** as the main grid (t
4650
When enabling the **Power Apps Grid Control**, an **Events** tab appears. Select the **Events** tab:
4751
1. Under the **Form Libraries** section, add the Form Libary from the web resource just created.
4852
2. Under the **Event Handlers** section, select the event **OnRecordSelect** and click Add, a popup will appear.
49-
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 make sure to check the option **Pass execution context as first parameter**.
53+
3. In the popup, select the form library just added and the Function name **Example.OnSelect**. This is the name of the JavaScript function created in the web resource, and make sure to check the option **Pass execution context as first parameter**.
5054

5155

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

0 commit comments

Comments
 (0)