1 - Select Actions
Last updated 18/07/2024
This documentation is to demonstrate how you can use Five's
The
To do this the following steps are performed:
- Create the StocksInSector query that filters the stock belonging to each sector.
- Create the Stocks In Sector data view to display the results when a slice of the pie chart is clicked.
- Create the ClickSector()function to execute theselectAction()function on theFiveobject and set theSectorvariable to filter the stocks belonging to the sector.
- Attach the ClickSector()function to the On Click event for the Investment by Sector chart area dataset.
- Create the PreviousAction()function to execute thepreviousAction()function on theFiveobject to return to the chart.
- Create an action button on the Stocks In Sector data view and attach the PreviousAction()function to the On Press event to return to us to the previous action when clicked.
The following short video demonstrates how the selectAction() and previousAction() functions work.
Add the StocksInSector Query
The StocksInSector query will filter the stocks belonging to the selected sector.
1. Click Data in the menu.2. Click Queries in the submenu.
![Queries menu item](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-query/queries-menu-item.png)
3. Click the Add Item button.
4. Type StocksInSector in the Data Source ID field.
5. Click in the Query field to open Five's Query Builder.
![Add the StocksInSector query](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-query/add-stocks-in-sector-query.png)
6. Click the SQL tab.
![SQL tab](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-query/sql-tab.png)
7. Click the Copy button for the syntax below.
SELECT
Stock.StockCode,
Stock.Name
FROM
Stock
INNER JOIN Sector ON Stock.SectorKey = Sector.SectorKey
WHERE
Sector.Name = ?
8. Paste the syntax in the SQL Editor.
The
9. Click the Save button in the SQL Editor app bar.
![Save button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-query/save-query.png)
10. Click the Parameters tab.
![Parameters tab](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-query/parameters-tab.png)
11. Click the Add Parameters button.
![Add Parameters button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-query/add-parameters-button.png)
12. Type Sector in the Parameter ID field.
13. Type
![Add the Sector parameter](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-query/add-sector-parameter.png)
14. Click the Save button in the form app bar.
![Save button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-query/save-sector-parameter.png)
15. Click the Save button in the form app bar above the list.
![Save button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-query/save-stocks-in-sector-query.png)
Add the Stocks in Sector Data View
The StocksInSector query will be used as the data source for the Stocks in Sector data view.1. Click Visual in the menu.
2. Click Data Views in the sub-menu.
![Data Views menu item](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-data-view/data-views-menu-item.png)
3. Click the Add Item button.
4. Type Stocks in Sector in the Title field.
5. Click the lookup icon in the Data Source field and select StocksInSector (Query).
![Add the Stocks in Sector data view](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-data-view/add-stocks-in-sector-data-view.png)
6. Click the Data Fields tab.
![Data Fields tab](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-data-view/data-fields-tab.png)
7. Select the Stock.StockCode record.
![Stock.StockCode record](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-data-view/stock-code-field.png)
8. Either click the Edit button in the form app bar, or click directly in the Caption field.
9. Change the value to Stock Code in the Caption field.
10. Click the Save button in the form app bar.
![Save button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-data-view/save-stock-code-field.png)
11. Select the Stock.Name record.
![Stock.Name record](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-data-view/name-field.png)
12. Change the value to Name in the Caption field.
13. Click the Save button in the form app bar.
![Save button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-data-view/save-name-field.png)
14. Click the Save button in the form app bar above the list.
![Save button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/stocks-in-sector-data-view/save-stocks-in-sector-data-view.png)
Add the ClickSector Function
When in Five's Code Editor you will be interacting with Five's API. In the
1. Click Logic in the menu.
2. Click Code Editor in the sub-menu.
![Code Editor menu item](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/click-sector-function/code-editor-menu-item.png)
3. Click the Add New Code button.
![Add New Code button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/click-sector-function/add-new-code-button.png)
4. Type ClickSector in the Function ID field.
5. Click the lookup icon in the Language field and select TypeScript.
6. Click the OKAY button.
![Add the ClickSector function](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/click-sector-function/add-click-sector-function.png)
7. Click the Copy button on the below code block.
8. Paste the code block over the template in the Code Editor.
function ClickSector(five: Five, context: any, result: FiveError) : FiveError {
five.setVariable('Sector', context.xValue);
five.selectAction('StocksinSector');
return five.success(result);
}
9. Click the Save Current Tab button.
![Save Current Tab button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/click-sector-function/save-click-sector-function.png)
Attach the ClickSector Function
The Investment Analysis chart record has two chart area datasets. We need to attach the
2. Click Charts in the sub-menu.
![Charts menu item](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-click-sector-function/charts-menu-item.png)
3. Select the Investment Analysis record in the list.
4. Click the Datasets tab.
![Datasets tab](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-click-sector-function/datasets-tab.png)
5. Select the InvestmentBySector (Query) record.
![InvestmentBySector (Query) record](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-click-sector-function/investment-by-sector-query-record.png)
6. Click the Chart Area Datasets tab.
![Chart Area Datasets tab](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-click-sector-function/chart-area-datasets-tab.png)
7. Select the Investment by Sector record.
![Investment by Sector record](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-click-sector-function/investment-by-sector-record.png)
8. Click the Events tab.
![Events tab](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-click-sector-function/events-tab.png)
9. Either click the Edit button in the form app bar, or click directly in the On Click field.
10. Click the lookup icon in the On Click field and select ClickSector.
![On Click event](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-click-sector-function/add-on-click-event.png)
11. Click the Save button in the form app bar.
![Save button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-click-sector-function/save-on-click-event.png)
12. Click the Save button in the form app bar above the list.
![Save button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-click-sector-function/save-investment-analysis-chart.png)
Add the PreviousAction Function
When in Five's Code Editor you will be interacting with Five's API. In the
2. Click Code Editor in the sub-menu.
![Code Editor menu item](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/previous-action-function/code-editor-menu-item.png)
3. Click the Add New Code button.
![Add New Code button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/previous-action-function/add-new-code-button.png)
4. Type PreviousAction in the Function ID.
5. Click the lookup icon in the Language field and select TypeScript.
6. Click the OKAY button.
![Add the PreviousAction function](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/previous-action-function/add-previous-action-function.png)
7. Click the Copy button on the below code block.
function PreviousAction(five: Five, context: any, result: FiveError) : FiveError {
five.previousAction();
return five.success(result);
}
8. Paste the code block over the template in the Code Editor.
9. Click the Save Current Tab button.
![Save Current Tab button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/previous-action-function/save-previous-action-function.png)
Add an Action Button
The Stocks in Sector data view needs an action button with the
2. Click Data Views in the sub-menu.
![Data Views menu item](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-previous-action-function/data-views-menu-item.png)
3. Select the Stocks in Sector record.
4. Click the Action Buttons tab.
![Action Buttons tab](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-previous-action-function/action-buttons-tab.png)
5. Click the Add Action Buttons button.
![Add Action Buttons button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-previous-action-function/add-action-buttons-button.png)
6. Type Back To Chart in the Caption field.
7. Click the Events tab.
![Events tab](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-previous-action-function/events-tab.png)
8. Click the lookup icon in the On Press field and select PreviousAction.
9. Click the Save button in the form app bar.
![Save button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-previous-action-function/save-previous-action-event.png)
10. Click the Save button in the form app bar above the list.
![Save button](/2.7/img/learning-resources/portfolio/intermediate/select-and-previous-actions/attach-previous-action-function/save-stocks-in-sector-query.png)